gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:09:37 25 4
gpt4 key购买 nike

我正在尝试在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com