1
votes

I have error handling set up in IIS 7 to forward to a 404 page, but the querystring does not ever appear to be passed over.

For example, this page does not exist so it directs to the 404 page:

www.mysite.com/nonexistingpage.aspx?id=1

On the 404 page, in the page_load, I cannot access id=1 because it doesn't seem like it's ever reaching the 404 page. So, trying to get it using these methods doesn't work:

Request.UrlReferrer.PathAndQuery
Request.ServerVariables["HTTP_REFERER"]

In IIS, my Path is entered as: /404.aspx and the Type is set to: Execute URL. How can I ensure the query string will be passed to the 404 page?

Edit: In Fiddler, the redirection is: /404.aspx?aspxerrorpath=/nonexistingpage.aspx, so this confirms it's definitely not being passed over.

1

1 Answers

1
votes

Are you using ASP.NET error pages or IIS error pages? From the fact you talk about redirection in Fiddler I think you are using ASP.NET error pages but ExecuteURL suggests you use IIS error pages. Or maybe you mixed both with ASP.NET taking the upper hand.

The best option is to use IIS error pages for the 404 page. This allows you to to do what you want:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors>
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/404.aspx" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

Now, when /404.aspx is called for your non existing pages, the query string is set to:

404;http://www.mysite.com/nonexistingpage.aspx?id=1