ASP.NET MVC Error Handling - Remove aspxerrorpath

前端 未结 5 1442
别那么骄傲
别那么骄傲 2020-12-30 22:45

I\'m working on some error handling in my MVC app, and I\'d like to change asperrorpath to something that doesn\'t give away the fact that I\'m using .NET... so

相关标签:
5条回答
  • 2020-12-30 23:29

    The are many ways you can solve your problem. It depends what you want.

    1. You can edit section in your web.config And write default link for redirecting on error and also specify different links for different error like <error statusCode="403" redirect="NoAccess.htm" />
    2. You can use HandleError attribute for your Controller/Actions. You can read about it here.
    0 讨论(0)
  • 2020-12-30 23:31

    Just add dummy query string to your .htm pages as below.

    <customErrors mode="On" defaultRedirect="errorpage.htm?error=1" >
          <error statusCode="404" redirect="filenotfound.htm?error=1" />
    </customErrors>
    

    Check with fiddler, the asperrorpath query string does not appear anymore and referrer of errorpage.htm is completely clean.

    0 讨论(0)
  • 2020-12-30 23:37

    my wprk around is using

    route.MapRoute("NotFound", "{*url}", new {controller = "Home", action = "NotFound"})
    

    At the bottom most, which I have NotFound action in HomeController. It will simply catch all other urls.

    0 讨论(0)
  • 2020-12-30 23:39

    Add redirectMode="ResponseRewrite" to the customErrors section. That worked for me.

    0 讨论(0)
  • 2020-12-30 23:49

    By supplying custom query string, your aspxerrorpath won't show up.

    Check the original answer from this link: how to prevent “aspxerrorpath”

    0 讨论(0)
提交回复
热议问题