c# - 如何找出 iis7 中的 404 错误处理程序中缺少哪个请求路径?

标签 c# asp.net iis iis-7 httphandler

我正在尝试在 iis 7 中创建自定义错误处理程序。

web.config httpErrors 部分:

<httpErrors>
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" path="/path/to/handlerwebservice" responseMode="ExecuteURL" />
</httpErrors>

web.config httpHandler 来处理错误:

<add path="*/path/to/handlerwebservice"          verb="GET,HEAD"     type="WebServices.Image404Handler, WebServices"          validate="false" />

Image404Handler C#代码:

public void ProcessRequest(HttpContext context)
{
    string requestpath;
    if (context.Request.QueryString.AllKeys.Contains("aspxerrorpath"))
    {
        requestpath = context.Request.QueryString["aspxerrorpath"];
    }
    else
    {
        requestpath = context.Request.Path;
    }

    // more code not really relevant here
}

我不知道如何获取导致 404 错误触发的请求的路径。在 IIS 6 中,Visual Studio 2008 使用此路径被添加到查询字符串中的 aspxerrorpath。

我无法进行远程调试,所以我在这里询问是否有人知道该怎么做。

最佳答案

我自己找到了答案。

使用 HttpСontext.Request.RawUrl 而不是 HttpСontext.Request.Path

关于c# - 如何找出 iis7 中的 404 错误处理程序中缺少哪个请求路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/705934/

相关文章:

c# - 我可以在 Xamarin.iOS 项目中使用 T4 文本生成吗?

c# - 无法通过 IIS 访问 aspx 页面

asp.net - 如何强制编译 ASP.NET MVC View ?

c# - 如何在 Xamarin 中发送 POST 请求?

c# - 在 C# 中是否有简写 If-Then-Else 的版本(cond?VB.Net 中的 : b),?

c# - 如何在 DotNetNuke 中以编程方式创建文件夹并为其分配权限?

asp.net - 使用传输编码 : chunked fails in IIS 8. 5 Web API 进行 POST

node.js - 使用 iisnode、nodejs 和 node-soap 库时 Win32 应用程序无效

c# - PRISM中的复合 View 导航

asp.net - 在 ASP.NET 中使用母版页