c# - 从 Visual Studio 调试 HTTP 处理程序

标签 c# visual-studio-2010 httphandler visual-studio-debugging

我正在尝试在 Visual Studio 中调试 HTTP 处理程序,但断点未命中。有人知道如何在 Visual Studio 中调试 HTTP 处理程序吗?

我在 Windows 7 机器上使用 VS 2010 Premium.NET 4.0。在我的 Web 应用程序中,我在 /HTTPHandler/TrackingHandler.cs

中有一个 HTTP 处理程序

以下是我的网络配置文件:

<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);
              .......
         }
     }
}

我使用 Visual Studio 调试 中的任意随机页面启动我的 Web 应用程序,使用内置 Web 服务器。然后我手动编辑 URL 以指向 /tx/目录 和它后面的一些随机字符串。 例如我当前的 URL 看起来像 http://localhost:53699/tx/sdfs 我认为这应该拉起 ProcessRequest() 但事实并非如此。

如果有任何想法,我将不胜感激。

哦。哦。

编辑:附加信息

Project PropertiesWeb 选项卡 中,我选择了 Don't open a page。等待来自外部应用程序的请求。我还遇到了 System.Web.HttpException,因此我转到了调试 -> 异常 -> 公共(public)语言运行时> 并选中 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 应用程序,然后 attach Visual Studio 到 IIS,您就可以进行调试了。

如果您不想或不能部署到 IIS(调试 HTTP 处理程序时,我配置 Post Build 脚本以将项目发布到 IIS),您可以通过将项目的启动选项设置为 '不要打开页面'并将 Visual Studio 附加到 aspnet_wp.exe

并且不要忘记以管理员身份运行 Visual Studio,否则附加将不起作用。

关于c# - 从 Visual Studio 调试 HTTP 处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11085648/

相关文章:

c# - 使用 C# .Net 访问 SQL Server 数据库的最佳方式

c# - 发送包含相同附件的多封电子邮件

c# - 在 Linux 上的 Azure Web App 中运行 dotnet core docker 镜像时,找不到与命令 "dotnet-/../.dll"匹配的可执行文件

vb.net - 项目模块 : Filtering Data in Crystal Reports?(按日、月、年)

jquery - 当用户控件通过 JQuery ajax 调用异步加载并多次加载时,Ajax 控件已停止工作

c# - 在 MVC 中更新实体属性

asp.net - 有没有办法真正禁用 ASP.NET 开发服务器?

c# - 发现重复符号 'WixAction:InstallExecuteSequence/RemoveExistingProducts'。这通常意味着 ID 重复

asp.net - 帮助我理解网络方法?

asp.net-mvc-2 - Web 托管告诉我需要在我的 web.config 中为静态内容添加 http 处理程序?