【问题标题】:How do I find out which request path is missing in a 404 error handler in iis7?如何找出 iis7 的 404 错误处理程序中缺少哪个请求路径?
【发布时间】:2010-10-16 21:31:11
【问题描述】:

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

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

【问题讨论】:

  • if(String.IsNullOrEmpty(Request["aspxerrorpath"]) ...

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


【解决方案1】:

我自己找到了答案。

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

【讨论】:

    猜你喜欢
    • 2011-09-26
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 2011-01-13
    相关资源
    最近更新 更多