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