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

后端 未结 11 760
夕颜
夕颜 2020-12-29 03:36

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



        
相关标签:
11条回答
  • 2020-12-29 03:39

    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.

    0 讨论(0)
  • 2020-12-29 03:41

    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.

    0 讨论(0)
  • 2020-12-29 03:42

    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.
    }
    
    0 讨论(0)
  • 2020-12-29 03:43

    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.

    0 讨论(0)
  • 2020-12-29 03:43

    I use javascript like

    if (location.search != "") { window.location.href = "/404.html"; } 
    
    0 讨论(0)
  • 2020-12-29 03:44

    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>
    
    0 讨论(0)
提交回复
热议问题