Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent "aspxerrorpath" being passed as a query string to ASP.NET custom error pages

In my ASP.NET web application, I have defined custom error pages in my web.config file as follows:

<customErrors mode="On" defaultRedirect="~/default.html">      <error statusCode="404" redirect="~/PageNotFound.html" /> </customErrors> 

In the case of a 404 error, my site redirects to the default.html page, but it passes "aspxerrorpath" as a query string parameter to the custom error page as follows:

http://www.example.com/default.html?aspxerrorpath=/somepathcausederror/badpage.aspx 

I don't want that behavior. I want the redirect URL to simply read:

http://www.example.com/default.html 

Is there a way to achieve this?

like image 769
DSharper Avatar asked Nov 19 '10 04:11

DSharper


People also ask

Which of the following attribute of the customErrors section is used to show custom error page in asp net?

The <customErrors> section in Web. config has two attributes that affect what error page is shown: defaultRedirect and mode . The defaultRedirect attribute is optional. If provided, it specifies the URL of the custom error page and indicates that the custom error page should be shown instead of the Runtime Error YSOD.

What is Aspxerrorpath?

The aspxerrorpath parameter is appended to the URL specified in defaultRedirect to help identify the page that caused the error.

What is custom error in asp net?

OFF: ASP.NET uses its default error page for both local and remote users in case of an error. ON: Custom error will be enabled for both local as well as remote client. REMOTE ONLY: The custom error page will be shown to a remote user only, the local user will get the built-in error page.


1 Answers

If you supply your own query string variable when specifying the path, then .NET will NOT tack on the "aspxerrorpath". Who knew?

For example:

<customErrors mode="On" defaultRedirect="errorpage.aspx?error=1" > 

This will do the trick. I had to add this to a bunch of apps since URLScan for IIS by default rejects anything with "aspxerrorpath" in it anyway.

like image 196
Matt J. Avatar answered Sep 20 '22 14:09

Matt J.