예제 #1
0
 internal ConfigErrorFormatter(System.Configuration.ConfigurationException e)
     : base(e.Filename, null, e.Line)
 {
     _e = e;
     PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_PRE_PROCESSING);
     PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_TOTAL);
     _message = e.BareMessage;
 }
예제 #2
0
 internal ConfigErrorFormatter(ConfigurationException e) : base(null, e.Filename, null, e.Line)
 {
     this._adaptiveMiscContent = new StringCollection();
     this._e = e;
     PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_PRE_PROCESSING);
     PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_TOTAL);
     this._message = HttpUtility.FormatPlainTextAsHtml(e.BareMessage);
     this._adaptiveMiscContent.Add(this._message);
 }
예제 #3
0
        // ctor used in HttpRuntime
        internal HttpContext(HttpWorkerRequest wr, bool initResponseWriter)
        {
            _wr = wr;
            Init(new HttpRequest(wr, this), new HttpResponse(wr, this));

            if (initResponseWriter)
            {
                _response.InitResponseWriter();
            }

            PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_EXECUTING);
        }
        private HttpWorkerRequest DequeueRequest(bool localOnly)
        {
            HttpWorkerRequest wr = null;

            while (_count > 0)
            {
                lock (this) {
                    if (_localQueue.Count > 0)
                    {
                        wr = (HttpWorkerRequest)_localQueue.Dequeue();
                        _count--;
                    }
                    else if (!localOnly && _externQueue.Count > 0)
                    {
                        wr = (HttpWorkerRequest)_externQueue.Dequeue();
                        _count--;
                    }
                }

                if (wr == null)
                {
                    break;
                }
                else
                {
                    PerfCounters.DecrementGlobalCounter(GlobalPerfCounter.REQUESTS_QUEUED);
                    PerfCounters.DecrementCounter(AppPerfCounter.REQUESTS_IN_APPLICATION_QUEUE);
                    if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Infrastructure))
                    {
                        EtwTrace.Trace(EtwTraceType.ETW_TYPE_REQ_DEQUEUED, wr);
                    }

                    if (!CheckClientConnected(wr))
                    {
                        HttpRuntime.RejectRequestNow(wr, true);
                        wr = null;

                        PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_DISCONNECTED);
                        PerfCounters.IncrementCounter(AppPerfCounter.APP_REQUEST_DISCONNECTED);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(wr);
        }
예제 #5
0
        private void QueueRequest(HttpWorkerRequest wr, bool isLocal)
        {
            lock (this) {
                if (isLocal)
                {
                    _localQueue.Enqueue(wr);
                }
                else
                {
                    _externQueue.Enqueue(wr);
                }

                _count++;
            }
            PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_QUEUED);
            PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_IN_APPLICATION_QUEUE);
        }
 private void QueueRequest(HttpWorkerRequest wr, bool isLocal)
 {
     lock (this)
     {
         if (isLocal)
         {
             this._localQueue.Enqueue(wr);
         }
         else
         {
             this._externQueue.Enqueue(wr);
         }
         this._count++;
     }
     PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_QUEUED);
     PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_IN_APPLICATION_QUEUE);
     if (EtwTrace.IsTraceEnabled(4, 1))
     {
         EtwTrace.Trace(EtwTraceType.ETW_TYPE_REQ_QUEUED, wr);
     }
 }
        private HttpWorkerRequest DequeueRequest(bool localOnly)
        {
            HttpWorkerRequest workerRequest = null;

            while (this._count > 0)
            {
                lock (this)
                {
                    if (this._localQueue.Count > 0)
                    {
                        workerRequest = (HttpWorkerRequest)this._localQueue.Dequeue();
                        this._count--;
                    }
                    else if (!localOnly && (this._externQueue.Count > 0))
                    {
                        workerRequest = (HttpWorkerRequest)this._externQueue.Dequeue();
                        this._count--;
                    }
                }
                if (workerRequest == null)
                {
                    return(workerRequest);
                }
                PerfCounters.DecrementGlobalCounter(GlobalPerfCounter.REQUESTS_QUEUED);
                PerfCounters.DecrementCounter(AppPerfCounter.REQUESTS_IN_APPLICATION_QUEUE);
                if (EtwTrace.IsTraceEnabled(4, 1))
                {
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_REQ_DEQUEUED, workerRequest);
                }
                if (this.CheckClientConnected(workerRequest))
                {
                    return(workerRequest);
                }
                HttpRuntime.RejectRequestNow(workerRequest, true);
                workerRequest = null;
                PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_DISCONNECTED);
                PerfCounters.IncrementCounter(AppPerfCounter.APP_REQUEST_DISCONNECTED);
            }
            return(workerRequest);
        }
        private void QueueRequest(HttpWorkerRequest wr, bool isLocal)
        {
            lock (this) {
                if (isLocal)
                {
                    _localQueue.Enqueue(wr);
                }
                else
                {
                    _externQueue.Enqueue(wr);
                }

                _count++;
            }

            PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_QUEUED);
            PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_IN_APPLICATION_QUEUE);
            if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Infrastructure))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_REQ_QUEUED, wr);
            }
        }
예제 #9
0
 public void IncrementCounter(AppPerfCounter counter)
 {
     PerfCounters.IncrementCounter(counter);
 }
예제 #10
0
        /// <include file='doc\HttpDebugHandler.uex' path='docs/doc[@for="HttpDebugHandler.ProcessRequest"]/*' />
        /// <devdoc>
        ///    <para>Drives web processing execution.</para>
        /// </devdoc>
        public void ProcessRequest(HttpContext context)
        {
            // Debugging must be enabled

            try {
                HttpDebugHandlerTimeLog.PrintTickDelta("Entered HttpDebugHandler");

                if (!HttpRuntime.DebuggingEnabled)
                {
                    context.Response.Write(HttpRuntime.FormatResourceString(SR.Debugging_forbidden, context.Request.Path));
                    context.Response.StatusCode = 403;
                    return;
                }

                // Check to see if it's a valid debug command.
                string command = context.Request.Headers["Command"];

                if (command == null)
                {
                    Debug.Trace("AutoAttach", "No debug command!!");
                    context.Response.Write(HttpRuntime.FormatResourceString(SR.Invalid_Debug_Request));
                    context.Response.StatusCode = 500;
                    return;
                }

                Debug.Trace("AutoAttach", "Debug command: " + command);

                if (string.Compare(command, "stop-debug", true, CultureInfo.InvariantCulture) == 0)
                {
                    context.Response.Write("OK");
                    return;
                }

                if (string.Compare(command, "start-debug", true, CultureInfo.InvariantCulture) != 0)
                {
                    context.Response.Write(HttpRuntime.FormatResourceString(SR.Invalid_Debug_Request));
                    context.Response.StatusCode = 500;
                    return;
                }

                // Request must be NTLM authenticated
                string authType  = context.WorkerRequest.GetServerVariable("AUTH_TYPE"); // go the metal
                string logonUser = context.WorkerRequest.GetServerVariable("LOGON_USER");

                Debug.Trace("AutoAttach", "Authentication type string: " + ((authType != null) ? authType : "NULL"));
                Debug.Trace("AutoAttach", "Logon user string: " + ((logonUser != null) ? logonUser : "******"));

                if (logonUser == null || logonUser.Length == 0 || authType == null || authType.Length == 0 || String.Compare(authType, "basic", true, CultureInfo.InvariantCulture) == 0)
                {
                    Debug.Trace("AutoAttach", "Invalid logon_user or auth_type string.");
                    context.Response.Write(HttpRuntime.FormatResourceString(SR.Debug_Access_Denied, context.Request.Path));
                    context.Response.StatusCode = 401;
                    return;
                }

                // Get the session ID
                String sessId = context.Request.Form["DebugSessionID"];

                Debug.Trace("AutoAttach", "DebugSessionID: " + ((sessId != null) ? sessId : "NULL"));

                if (sessId == null || sessId.Length == 0)
                {
                    context.Response.Write(HttpRuntime.FormatResourceString(SR.Invalid_Debug_ID));
                    context.Response.StatusCode = 500;
                    return;
                }

                string s = sessId.Replace(';', '&');

                HttpValueCollection valCol = new HttpValueCollection(s, true, true, Encoding.UTF8);
                string clsId = (string)valCol["autoattachclsid"];

                // Verify clsId
                bool isClsIdOk = false;
                if (clsId != null)
                {
                    for (int i = 0; i < validClsIds.Length; i++)
                    {
                        if (clsId.ToLower(System.Globalization.CultureInfo.InvariantCulture) == validClsIds[i])
                        {
                            isClsIdOk = true;
                            break;
                        }
                    }
                }
                if (isClsIdOk == false)
                {
                    context.Response.Write(HttpRuntime.FormatResourceString(SR.Debug_Access_Denied, context.Request.Path));
                    context.Response.StatusCode = 401;
                    Debug.Trace("AutoAttach", "Debug attach not attempted because of invalid CLSID.");
                    return;
                }

                // Attach the debugger
                HttpDebugHandlerTimeLog.PrintTickDelta("About to call into MDM");

                int rc = UnsafeNativeMethods.AttachDebugger(clsId, sessId, context.WorkerRequest.GetUserToken());

                HttpDebugHandlerTimeLog.PrintTickDelta("Returned from call to MDM");

                // If it's not S_OK, then we got a problem
                if (rc != 0)
                {
                    Debug.Trace("AutoAttach", "Debug attach failed! Return code: " + rc);
                    context.Response.Write(HttpRuntime.FormatResourceString(SR.Error_Attaching_with_MDM, "0x" + rc.ToString("X8")));
                    context.Response.StatusCode = 500;
                    return;
                }

                Debug.Trace("AutoAttach", "Debug attach successful!");

                // Everything ok -- increment counter, return something (not 204)
                PerfCounters.IncrementCounter(AppPerfCounter.DEBUGGING_REQUESTS);
                context.Response.Write("OK");

                // Set global flag for us
                HttpRuntime.VSDebugAttach = true;
            }
            finally {
                Debug.Trace("AutoAttach", "Http Debug attach done!");

                HttpDebugHandlerTimeLog.PrintTickDelta("Leaving HttpDebugHandler");
                HttpDebugHandlerTimeLog.Close();
            }
        }
예제 #11
0
 public void ProcessRequest(HttpContext context)
 {
     PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_NOT_FOUND);
     throw new HttpException(0x194, System.Web.SR.GetString("Path_not_found", new object[] { context.Request.Path }));
 }
 public void ProcessRequest(HttpContext context)
 {
     if (!HttpRuntime.DebuggingEnabled)
     {
         context.Response.Write(System.Web.SR.GetString("Debugging_forbidden", new object[] { context.Request.Path }));
         context.Response.StatusCode = 0x193;
     }
     else
     {
         string str = context.Request.Headers["Command"];
         if (str == null)
         {
             context.Response.Write(System.Web.SR.GetString("Invalid_Debug_Request"));
             context.Response.StatusCode = 500;
         }
         else if (StringUtil.EqualsIgnoreCase(str, "stop-debug"))
         {
             context.Response.Write("OK");
         }
         else if (!StringUtil.EqualsIgnoreCase(str, "start-debug"))
         {
             context.Response.Write(System.Web.SR.GetString("Invalid_Debug_Request"));
             context.Response.StatusCode = 500;
         }
         else
         {
             string serverVariable = context.WorkerRequest.GetServerVariable("AUTH_TYPE");
             if ((string.IsNullOrEmpty(context.WorkerRequest.GetServerVariable("LOGON_USER")) || string.IsNullOrEmpty(serverVariable)) || StringUtil.EqualsIgnoreCase(serverVariable, "basic"))
             {
                 context.Response.Write(System.Web.SR.GetString("Debug_Access_Denied", new object[] { context.Request.Path }));
                 context.Response.StatusCode = 0x191;
             }
             else
             {
                 string str4 = context.Request.Form["DebugSessionID"];
                 if (string.IsNullOrEmpty(str4))
                 {
                     context.Response.Write(System.Web.SR.GetString("Invalid_Debug_ID"));
                     context.Response.StatusCode = 500;
                 }
                 else
                 {
                     HttpValueCollection values = new HttpValueCollection(str4.Replace(';', '&'), true, true, Encoding.UTF8);
                     string str6 = values["autoattachclsid"];
                     bool   flag = false;
                     if (str6 != null)
                     {
                         for (int i = 0; i < validClsIds.Length; i++)
                         {
                             if (StringUtil.EqualsIgnoreCase(str6, validClsIds[i]))
                             {
                                 flag = true;
                                 break;
                             }
                         }
                     }
                     if (!flag)
                     {
                         context.Response.Write(System.Web.SR.GetString("Debug_Access_Denied", new object[] { context.Request.Path }));
                         context.Response.StatusCode = 0x191;
                     }
                     else
                     {
                         int num2 = UnsafeNativeMethods.AttachDebugger(str6, str4, context.WorkerRequest.GetUserToken());
                         if (num2 != 0)
                         {
                             context.Response.Write(System.Web.SR.GetString("Error_Attaching_with_MDM", new object[] { "0x" + num2.ToString("X8", CultureInfo.InvariantCulture) }));
                             context.Response.StatusCode = 500;
                         }
                         else
                         {
                             PerfCounters.IncrementCounter(AppPerfCounter.DEBUGGING_REQUESTS);
                             context.Response.Write("OK");
                         }
                     }
                 }
             }
         }
     }
 }
예제 #13
0
        private async Task <AspNetWebSocket> ProcessRequestImplAsync()
        {
            AspNetWebSocket webSocket = null;

            try {
                // SendResponse and other asynchronous notifications cannot be process by ASP.NET after this point.
                _root.WorkerRequest.SuppressSendResponseNotifications();

                // A flush is necessary to activate the WebSocket module so that we can get its pointer.
                //
                // DevDiv #401948: We can't allow a flush failure to propagate out, otherwise the rest of
                // this method doesn't run, which could leak resources (by not invoking the user callback)
                // or cause weird behavior (by not calling CompleteTransitionToWebSocket, which could corrupt
                // server state). If the flush fails, we'll wait to propagate the exception until a safe
                // point later in this method.
                ExceptionDispatchInfo flushExceptionDispatchInfo = DoFlush();

                // Create the AspNetWebSocket. There's a chance that the client disconnected before we
                // hit this code. If this is the case, we'll pass a null WebSocketPipe to the
                // AspNetWebSocket ctor, which immediately sets the socket into an aborted state.
                UnmanagedWebSocketContext unmanagedWebSocketContext = _root.WorkerRequest.GetWebSocketContext();
                WebSocketPipe             pipe = (unmanagedWebSocketContext != null) ? new WebSocketPipe(unmanagedWebSocketContext, PerfCounters.Instance) : null;
                webSocket = new AspNetWebSocket(pipe, _subProtocol);

                // slim down the HttpContext as much as possible to allow the GC to reclaim memory
                _httpContext.CompleteTransitionToWebSocket();

                // always install a new SynchronizationContext, even if the user is running in legacy SynchronizationContext mode
                AspNetSynchronizationContext syncContext = new AspNetSynchronizationContext(this);
                _httpContext.SyncContext = syncContext;

                bool webSocketRequestSucceeded = false;
                try {
                    // need to keep track of this in the manager so that we can abort if it the AppDomain goes down
                    AspNetWebSocketManager.Current.Add(webSocket);

                    // bump up the total count (the currently-executing count is recorded separately)
                    PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_TOTAL_WEBSOCKETS);

                    // Release the reference to the user delegate (which might just be a simple initialization routine) so that
                    // the GC can claim it. The only thing that needs to remain alive is the Task itself, which we're referencing.
                    Task task = null;
                    syncContext.Send(_ => {
                        task = _userFunc(new AspNetWebSocketContextImpl(new HttpContextWrapper(_httpContext), _root.WorkerRequest, webSocket));
                    }, null);

                    // Was there an exception from user code? If so, rethrow (which logs).
                    ExceptionDispatchInfo exception = syncContext.ExceptionDispatchInfo;
                    if (exception != null)
                    {
                        exception.Throw();
                    }

                    _userFunc = null;
                    await task.ConfigureAwait(continueOnCapturedContext : false);

                    // Was there an exception from the earlier call to DoFlush? If so, rethrow (which logs).
                    // This needs to occur after the user's callback finishes, otherwise ASP.NET could try
                    // to complete the request while the callback is still accessing it.
                    if (flushExceptionDispatchInfo != null)
                    {
                        flushExceptionDispatchInfo.Throw();
                    }

                    // Any final state except Aborted is marked as 'success'.
                    // It's possible execution never reaches this point, e.g. if the user's
                    // callback throws an exception. In that case, 'webSocketRequestSucceeded'
                    // will keep its default value of false, and the performance counter
                    // will mark this request as having failed.

                    if (webSocket.State != WebSocketState.Aborted)
                    {
                        webSocketRequestSucceeded = true;
                        PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_SUCCEEDED_WEBSOCKETS);
                    }
                }
                finally {
                    // we need to make sure the user can't call the WebSocket any more after this point
                    _isProcessingComplete = true;
                    webSocket.DisposeInternal();
                    AspNetWebSocketManager.Current.Remove(webSocket);

                    if (!webSocketRequestSucceeded)
                    {
                        PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_FAILED_WEBSOCKETS);
                    }
                }
            }
            catch (Exception ex) {
                // don't let the exception propagate upward; just log it instead
                WebBaseEvent.RaiseRuntimeError(ex, null);
            }

            return(webSocket);
        }