strangedeのブログ -15ページ目

strangedeのブログ

ブログの説明を入力します。

ASP.Net request processing initial adventure - Part 1 Prelude begins: Previous We understand that a request is issued from the client to the server to receive and process the entrance to ASP.Net process, we began to explore this ASP. Net core processing part of, with a strong anti-compilation tools, we will see a few familiar and unfamiliar terms (class): HttpRuntime, HttpWorkerRequest, HttpContext, HttpApplication like. First, the first entry: ISAPIRuntme.ProcessRequest () ISAPIRuntime entering entrance NET managed environment, which through the process a handle to the current ecb request stylistic memory address, the HTTP request packets packaged as a simple target HttpWorkerRequest then we often hear is various PR (ProcessRequest) method Mens Nike Free 3.0 Wool Skin Shoes Red Grey has. ① call ISAPIRuntime object ProcessRequest way into the ASP.NET processing through Reflector, we can see in this entry in ISAPIRuntime method: ProcessRequest② first create according ecb handle HttpWorkerRequest object encapsulates the original request packet on HttpWorkerRequest: prepared in Asp.Net request for processing, the object must be packaged as HttpWorkerRequest type, HttpWorkerRequest is an abstract type. ISAPIWorkerRequest created here is a type that inherits from HttpWorkerRequest class. [ComVisible (false)] public abstract class HttpWorkerRequest {// Fields private DateTime _startTime; private Guid _traceId; ......} CreateWorkerRequest method proceeds ISAPIWorkerRequest class, see the first version of the current judgment of the IIS server (IIS6 or IIS7?), and then create a suitable for different IIS specific WorkerRequest object, the default is InProc within the process, of course, there are also external OutOfProc process. internal static ISAPIWorkerRequest CreateWorkerRequest (IntPtr ecb, bool useOOP) {if (useOOP) {EtwTrace.TraceEnableCheck (EtwTraceConfigType.DOWNLEVEL, IntPtr.Zero); if (EtwTrace.IsTraceEnabled (5, 1)) {EtwTrace.Trace (EtwTraceType.ETW_TYPE_APPDOMAIN_ENTER, ecb, Thread.GetDomain () FriendlyName, null, false);.} return new ISAPIWorkerRequestOutOfProc (ecb);} int num = UnsafeNativeMethods.EcbGetVersion (ecb) \u0026 gt; \u0026 gt; 0x10; if (num \u0026 gt; = 7) {EtwTrace. TraceEnableCheck (EtwTraceConfigType.IIS7_ISAPI, ecb);} else {EtwTrace.TraceEnableCheck (EtwTraceConfigType.DOWNLEVEL, IntPtr.Zero);} if (EtwTrace.IsTraceEnabled (5, 1)) {EtwTrace.Trace (EtwTraceType.ETW_TYPE_APPDOMAIN_ENTER, ecb, Thread. GetDomain () FriendlyName, null, true);.} if (num \u0026 gt; = 7) {return new ISAPIWorkerRequestInProcForIIS7 (ecb);} if (num == 6) {return new ISAPIWorkerRequestInProcForIIS6 (ecb);} return new ISAPIWorkerRequestInProc (ecb );} Because HttpWorkerRequest class encapsulates the request packet is very primitive, very complicated, so Microsoft did not make it public out. Second, the second entry: HttpRuntime.ProcessRequest () HttpRuntime ASP.NET request processing is a second entrance. When a request comes in, the first to enter HttpRuntime, the HttpRuntime to decide how to handle the request. By default, machine.config and Web.config did not explicitly defined httpRuntime node, but the node is the default value, as follows: Nike Free 3.0 V4 \u0026 lt; httpRuntime apartmentThreading = \u0026 quot; false \u0026 quot; appRequestQueueLimit = \u0026 quot; 5000 \u0026 quot; delayNotificationTimeout = \u0026 quot ; 5 \u0026 quot; enable = \u0026 quot; true \u0026 quot; enableHeaderChecking = \u0026 quot; true \u0026 quot; enableKernelOutputCache = \u0026 quot; Nike Air Max true \u0026 quot; enableVersionHeader = \u0026 quot; true \u0026 quot; encoderType = \u0026 quot; System.Web.Util.HttpEncoder \u0026 quot; executionTimeout Mens Nike Free 3.0 Wool Skin Shoes Grey Yellow = \u0026 quot; 110 \u0026 quot; maxQueryStringLength = \u0026 quot; 2048 \u0026 quot ; maxRequestLength = \u0026 quot; 4096 \u0026 quot; maxUrlLength = \u0026 quot; 260 \u0026 quot; maxWaitChangeNotification = \u0026 quot; 0 \u0026 quot; minFreeThreads = \u0026 quot; Nike Lunareclipse 8 \u0026 quot; minLocalRequestFreeThreads = \u0026 quot; 4 \u0026 quot; relaxedUrlToFileSystemMapping = \u0026 quot; False \u0026 quot; Nike Free 3.0 V5 requestLengthDiskThreshold = \u0026 quot; 80 \u0026 quot; requestPathInvalidCharacters = \u0026 quot; \u0026 lt ;, \u0026 gt;, *,%, \u0026 amp;,:, \\ \u0026 quot; requestValidationMode = \u0026 quot; 4.0 \u0026 quot; requestValidationType = \u0026 quot; System.Web.Util.RequestValidator \u0026 quot; requireRootedSaveAsPath = \u0026 quot; true \u0026 quot; sendCacheControlHeader = \u0026 quot; true \u0026 quot; shutdownTimeout = \u0026 quot; 90 \u0026 quot; useFullyQualifiedRedirectUrl = \u0026 quot; false \u0026 quot; waitChangeNotification = \u0026 quot; 0 \u0026 quot; / \u0026 gt; In general, we can change the default value httpRuntime node in Web.config, as follows: \u0026 lt; configuration \u0026 gt; \u0026 lt; system.web \u0026 gt; Nike Air Max 95 Nike Free 3.0 V4 Men Women \u0026 lt; httpRuntime maxRequestLength = \u0026 quot; 4000 \u0026 quot; enable = \u0026 quot; True \u0026 quot; requestLengthDiskThreshold = \u0026 quot; 512 useFullyQualifiedRedirectUrl = \u0026 quot; True \u0026 quot; executionTimeout = \u0026 quot; 45 \u0026 quot; versionHeader = \u0026 quot; 1.1.4128 \u0026 quot; / \u0026 gt; \u0026 lt; /system.web\u0026gt; \u0026 lt; / configuration \u0026 gt; Nike Lunarglide+ 3 ① followed by the implementation of ProcessRequestNoDemand HttpRuntime HttpContext object encapsulation method HttpRuntime class has a static method called ProcessRequestNoDemand of. After initialization HttpWorkerRequest here and create an object, called HttpRuntime this ProcessRequestNoDemand methods. So, we go ProcessRequestNoDemand way, you can see the following code: internal static void ProcessRequestNoDemand (HttpWorkerRequest wr) {RequestQueue queue = _theRuntime._requestQueue; wr.UpdateInitialCounters (); if (queue = null!) {Wr = queue.GetRequestToExecute ( wr);} if (wr = null) {CalculateWaitTimeAndUpdatePerfCounter (wr);! wr.ResetStartTime (); ProcessRequestNow (wr);}} This method to start out a request to the request queue, and then update the reference counter information request, then HttpWorkerRequest object passed ProcessRequestNow method to process Air Max 2011 Womens Grey Red Black the request. Here we can also see _theRuntime this field, it is a static field HttpRuntime class is initialized in HttpRuntime static constructor. public Air Jordan Outlet sealed class HttpRuntime {// Fields ...... private static HttpRuntime _theRuntime; ......} to go back ProcessRequestNoDemand method, we see the final by ProcessRequestNow way to taking over. So, we go to look at ProcessRequestNow method: internal static void ProcessRequestNow (HttpWorkerRequest wr) {_theRuntime.ProcessRequestInternal (wr);} We see this method in turn calls the instance method _theRuntime of: ProcessRequestInternal, or the HttpWorkerRequest objects As an argument in the past. So, we then go ProcessRequestInternal this method, we found an important object: HttpContext object. private void ProcessRequestInternal (HttpWorkerRequest wr) {Interlocked.Increment (ref this._activeRequestCount); if (this._disposingHttpRuntime) {......} else {HttpContext context; try {context = new HttpContext (wr, false);} catch {try {wr.SendStatus (400, \u0026 quot; Bad Request \u0026 quot;); wr.SendKnownResponseHeader (12, \u0026 quot; text / html; charset = utf-8 \u0026 quot;); byte [] data = Encoding.ASCII.GetBytes (\u0026 quot; \u0026 lt; html \u0026 2015 Nike Free 5.0 gt; \u0026 lt; body \u0026 gt; Bad Request \u0026 lt; / body \u0026 gt; \u0026 lt; / html \u0026 gt; \u0026 Mens Nike Free Run 3 Shoes Grey 3 quot;); wr.SendResponseFromMemory (data, data.Length); wr.FlushResponse (true); wr.EndOfRequest (); return;} finally {Interlocked.Decrement (ref this._activeRequestCount);}} ......}} HttpContext in the constructor, the object is created based on HttpWorkerRequest Nike Air Max 95 Women HttpContext object, which is an important Http context object, two important types The field also will be initialized: HttpRequest objects and HttpResponse objects. I believe everyone during ASP.NET development, often uses examples of these two types. For example, we can get through HttpContext.Current to this instance, and the instance will survive throughout the life cycle, we can get through it to some commonly used objects, such as Request, Response, Session and the like. ② get a specific HttpApplication instance let us return HttpRuntime of ProcessRequestInternal this method again, after just HttpContext object is created, followed by what they did HttpApplicationFactory? Let's look at the Mens Nike Free Run 3 Shoes Blue 3 source: private void ProcessRequestInternal (HttpWorkerRequest wr) {Interlocked.Increment (ref this._activeRequestCount); if (this._disposingHttpRuntime) {......} else {HttpContext context; ...... \u0026 lt ; strong \u0026 gt; IHttpHandler applicationInstance \u0026 lt; / strong \u0026 gt; \u0026 lt; strong \u0026 gt; = HttpApplicationFactory.GetApplicationInstance (context); ...... \u0026 lt; / strong \u0026 gt; if (applicationInstance is IHttpAsyncHandler) {IHttpAsyncHandler handler2 = (IHttpAsyncHandler) applicationInstance; context. AsyncAppHandler = handler2; handler2.BeginProcessRequest (context, this._handlerCompletionCallback, context);} else {applicationInstance.ProcessRequest (context); this.FinishRequest (context.WorkerRequest, context, null);} ......}} First We saw a very familiar words: IHttpHandler, our ashx, aspx not all realize this IHttpHandler interface it? So, let's look at the phrase: IHttpHandler applicationInstance