解决网站发布404返回200,301等状态
1、在404.aspx中加入代码: 
Response.Status = "404 Moved Permanently"; 
如果你没有做伪静态,或者没加脚本映射,以上完全没有问题,不必往下看了。如果做了伪静态,那么404页面返回的状态码仍然为302,请看第二步。 
2、在 Global.asax 中加入下面的代码: 
代码如下:
[html] view plain copy
- protected void Application_Error(object sender, EventArgs e)
- {
- //在出现未处理的错误时运行的代码
- this.FileNotFound_Error();
- }
- /// <summary>
- /// 404错误处理
- /// </summary>
- private void FileNotFound_Error()
- {
- HttpException erroy = Server.GetLastError() as HttpException;
- if (erroy != null && erroy.GetHttpCode() == 404)
- {
- Server.ClearError();
- string path = "~/404.aspx";
- Server.Transfer(path);
- //Context.Handler = PageParser.GetCompiledPageInstance(path, Server.MapPath(path), Context);
- }
- }
iis里要配置在第二个
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号