How to find out which request path is missing in the 404 error handler in iis7?

I am trying to create my own error handler in iis 7.

web.config httpErrors section:

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

web.config httpHandler to handle the error:

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

Image404Handler C # code:

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
}

I cannot figure out how to get the path to the request that caused the 404 error. In IIS 6, this Visual Studio 2008 uses this path added to the aspxerrorpath in the request.

I cannot get remote debugging to work, so I ask here if anyone knows what to do.

+3
source share
1 answer

I myself found the answer.

Use Httpontext.Request.RawUrlinsteadHttpontext.Request.Path

+4
source

Source: https://habr.com/ru/post/1705723/


All Articles