ASP.NET MVC Error Handling - Remove aspxerrorpath

2019-02-07 19:14发布

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?

5条回答
Lonely孤独者°
2楼-- · 2019-02-07 20:04

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楼-- · 2019-02-07 20:04

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.
查看更多
Summer. ? 凉城
4楼-- · 2019-02-07 20:06

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

查看更多
做个烂人
5楼-- · 2019-02-07 20:11

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

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

查看更多
你好瞎i
6楼-- · 2019-02-07 20:11

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.

查看更多
登录 后发表回答