In my ASP.NET web application, I have defined custom error pages in my web.config file as follows:
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.
Add redirectMode="ResponseRewrite"
in the Custom Error like this,
<customErrors mode="On" defaultRedirect="~/NotFound">
<error statusCode="404" redirect="~/NotFound" redirectMode="ResponseRewrite"/>
</customErrors>
this solution works for me.
If you want to resolve or handle error request you can insert into Handler try catch statement. like this:
try {
// Block of code that generate error
}
catch(Exception e) {
// Block of code to handle errors ||| HERE you can put error in your response and handle it without get xhr redirect error.
}
My first thought would be to create a HttpHandler which catches url's with aspxerrorpath
in it, and strips it. You could probably do the same with the rewrite module in IIS7 as well.
I use javascript like
if (location.search != "") { window.location.href = "/404.html"; }
You could just send your own url params to the error page
<customErrors mode="On" defaultRedirect="~/default.html?404">
<error statusCode="404" redirect="~/PageNotFound.html?404" />
</customErrors>