簡體   English   中英

從Visual Studio調試HTTP處理程序

[英]Debugging a HTTP Handler from Visual Studio

我正在嘗試在Visual Studio中調試HTTP處理程序 ,並且斷點沒有命中。 有誰知道如何在Visual Studio中調試HTTP處理程序?

我在Windows 7計算機上使用VS 2010 Premium.NET 4.0 在我的Web應用程序中,我在/HTTPHandler/TrackingHandler.cs中有一個HTTP處理程序。

以下是我的Web配置文件中:

<system.webServer>
        <handlers>
            <add name="TrackingHandler" path="/tx/*" verb="*" type="ProjectNamespace.TrackingHandler" resourceType="Unspecified" preCondition="integratedMode" />
        </handlers>
  </system.webServer>

我的HTTP處理程序如下所示

namespace ProjectNamespace
{
    public class TrackingHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
             //Breakpoint on the very first line below
             string tracker = Path.GetFileName(context.Request.PhysicalPath);
              .......
         }
     }
}

我使用內置的Web服務器Visual Studio調試中使用任意隨機頁面啟動Web應用程序。 然后,我手動編輯URL以指向/ tx /目錄,並在其后輸入一些隨機字符串。 例如,我當前的URL看起來像http:// localhost:53699 / tx / sdfs 我認為這應該在ProcessRequest()的第一行上拉斷點,但事實並非如此。

我將不勝感激。

面向對象

編輯:附加信息

在“ 項目屬性 ”的“ Web”選項卡中 ,我選擇了“不打開頁面”。 等待來自外部應用程序的請求。 我也得到了System.Web.HttpException ,所以我去了Debug-> Exceptions-> Common Language Runtime並選中了System.Web旁邊的框。

以下是我的堆棧跟蹤。 它似乎沒有到達我的處理程序。 我在Web配置中定義有誤嗎?

>   System.Web.dll!System.Web.StaticFileHandler.GetFileInfo(string virtualPathWithPathInfo, string physicalPath, System.Web.HttpResponse response) + 0x1f7 bytes    
    System.Web.dll!System.Web.StaticFileHandler.ProcessRequestInternal(System.Web.HttpContext context = {System.Web.HttpContext}, string overrideVirtualPath) + 0xc7 bytes  
    System.Web.dll!System.Web.DefaultHttpHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback callback = {Method = {System.Reflection.RuntimeMethodInfo}}, object state = null) + 0x15c bytes   
    System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x2d7 bytes    
    System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.CallHandlerExecutionStep}, ref bool completedSynchronously = true) + 0xb9 bytes  
    System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x13e bytes  
    System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0xf8 bytes  
    System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr = {Microsoft.VisualStudio.WebHost.Request}) + 0x1a2 bytes  
    System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x7d bytes  
    System.Web.dll!System.Web.HttpRuntime.ProcessRequest(System.Web.HttpWorkerRequest wr) + 0x47 bytes  
    WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Request.Process() + 0x17b bytes 
    WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Microsoft.VisualStudio.WebHost.Connection conn = {System.Runtime.Remoting.Proxies.__TransparentProxy}) + 0x6c bytes 
    [Appdomain Transition]  
    WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(object acceptedSocket) + 0x83 bytes   
    mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x2d bytes 
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xb0 bytes    
    mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x5a bytes 
    mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x147 bytes  
    mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x2d bytes    
    [Native to Managed Transition]

將處理程序發布到其自己的IIS應用程序,然后 Visual Studio 附加到IIS,您就可以開始調試了。

如果您不想或無法部署到IIS(調試HTTP處理程序時,我將Post Build腳本配置為將項目發布到IIS),則可以通過將項目的啟動選項設置為“不”來調試Cassini。打開頁面”並將Visual Studio附加到aspnet_wp.exe

並且不要忘記以管理員身份運行Visual Studio,否則附加將無法進行。

當所有其他方法均失敗時,可以使用DebugBreak(),__debugBreak()或_asm int 3在應用程序中生成調試中斷 。執行該命令並安裝了MSDev時,您將得到一個對話框,詢問您是否要終止或調試。 這使您可以立即運行並在以后附加,並且無需知道要附加什么即可工作。

如果從選項工具->附加到進程並選擇所需的進程,將進程附加到斷點(例如w3wp.exe),則會遇到斷點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM