/// <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(); } }
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"); } } } } } } }