asp.net自定义404页面

网上有很多方法,不过大体相同,这只是其中一个方法,亲测有效,记录后面可能会有用

1.

先写好一个404页面 404.aspx在项目根目录下

然后在配置文件中添加

 <!-- 注意这个模式,redirectMode默认为ResponseRedirect  这个模式会产生一个302跳转,对爬虫非常不友好,所以我们使用redirectMode="ResponseRewrite"-->
<customErrors mode="On" redirectMode="ResponseRewrite" >
<error statusCode="404" redirect="~/404.aspx"/>
</customErrors>

至此就已经可以完成对.aspx的过滤了

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABBAAAAAiCAIAAABp+r0SAAAOUklEQVR4nO1dzW7bSBLOY8h+gH0NSQ+xgAXsXCnkYPsaX/YgCRgE8gNIMwPsTYGMkJCRXBw5CWwnsQ+JqUCeAeYiLeaQQ5DRysYAo8EI8B6abFb/kBJtSuqWvw91sKkm2SxWVdfX1S09Gl/fzJKLxk7NZX+fN7d3mh9mn2KSeLWtqkePfGjubjcvyNPtNs75p16lRP81Sz5+ulx5HyD3F7daqng34+ubD81dwTjPmw3vxq1KFiiZKMRWgf+mlGDo+dDc3SqVtkqlrao39mrb1ZowDJ03t9mnsoTDFmQ+uYt9nje3xeE1fHE8ZEV/8/fIot9C+pOq58nJzHmz0rwQYrVoYNvNC8H2qrVK+HfFY6brVRaZL60unlw0dnYbnubVc3WFzaJ/PzR3t5abPar6aTR/+P7pU/b3pd8rP34cd+6TvT3+onmz758+ZUeOXnXZdb5/+vToVffS7z3Z21vRu5Blq1RSn4X1k/X80u/RNk/29o5edbWXetZuU4M/etV9NFcnvBoLvh+au3O6ujFy0dgpEXpwM5YJg+DS4UeGpmhIONZFLho7YQKkfOpWdxvnYQNFbHNASCTw35Ry0dipVaqizZ83t7kXsHRtZ3dbww3IPBdkPpnLPr2aNi4l8rQ75s0rJAx81sat6kLueXObTiwGk5JeJUqT1pkw8HkueW5LZo8CYRhfe5Xljl+qfp612zyzP3rVlbJ8lklzufR70qflx49Zes1PZIl4AvFYuTxrtzlH4l2lT1d+/Fh6Uk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dj/HpdXHcU9ookBNy7lMbE8aZT6ZTgIliSBNgKddMzqyT8/fffrJgwGo263S7/lqSjo6NOp9Pv95UrzbMkKfLNuietHpmvwhC3JEkfOpS6QbQEUVyLQjc9R9E4oSYJwrAkrD9hkHZOSkvvBDvkxk+9QFxcFx7jJurvFzUbhKb2VBiS9SM1UJC86Xm6Cv1k9S1J8RWGsHBKF01891PiiWnumwbrRxhopq6xj6wJQ3BNSgxifofBQsKg+b5k8hsX+2Io3w/3OxaiqK7dBk2DuzzZr9m4Vle/s1naBs1TBEK463TXivBevHKuUK+rB+nkKBIIwE5IA/xoNDo+Pj44OLi+vr4N8euvv7JdDQcHB4eHh91udzQaKVeS5+Zj92Lxg8Tf63NWGKZinOQhMSZ05ORNz4p3s5OjSRx1vai2w7HjBZAt7kEYwpcYbXrWtDeBMAijpFLdknbwB2fQn3Ka8TsD0R4P8VcLFmK9y9dP8netziQM06XrZ3WEQfuVD+nvmwZrQhiArLD+v+yIX5wF1heq/3758qXVap2dnXHC8Ndffx0fH7948eL9+/eHh4dfvnxZSVeBBwjTxhfT+mMaoJ9kZEkY0uBBf0sSYA7WP0CAMADrC63/DofD169fX11dXV9ff/v2rdfrsZ0Mp6eng8Fg+Z0EHixMG19M649pgH6SgV96zvy+IAw2Yf0DBAgDsL6I89/JZNLv909OTjqdTqfTOTk56ff7k8lkyd0DHjhMG19M649pgH6SAcKQ+X1BGGwCAgQA2Av4L2AyTLNP0/pjGqCfZIAwZH5fEAabgAABAPYC/guYDNPs07T+mAboJxkgDJnfF4TBJiBAAIC9gP8CJsM0+zStP6YB+kkGCEPm9wVhsAkIEABgL+C/gMkwzT5N649pgH6SAcKQ+X3/Dz4z95SQ5OdbAAAAAElFTkSuQmCC" alt="" />

2.这个时候我们输入****/demo.html还是会跳转到iis的404页面

要想支持所有的路径

请进入iis配置

asp.net自定义404页面

asp.net自定义404页面

这样以来所有的路径都支持了

参考:http://blog.gkong.com/shotgun_174429.ashx

上一篇:python操作三大主流数据库(7)python操作mongodb数据库①mongodb的安装和简单使用


下一篇:python操作三大主流数据库(13)python操作redis之新闻项目实战①新闻数据的导入