ASP.NET MVC Error Handling - Remove aspxerrorpath

2019-02-07 19:43发布

问题:

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... something like path

Can anyone give me some direction on how to change that out?

回答1:

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



回答2:

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.



回答3:

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.


回答4:

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

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



回答5:

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.