3

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

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

4

1 回答 1

4

我自己找到了答案。

使用HttpСontext.Request.RawUrl代替HttpСontext.Request.Path

于 2009-04-02T07:03:36.627 回答