2012-02-07 25 views
0

的Application_Error未发布任何网站,我也取得了自定义错误模式的web配置关闭,烧成后仅远程我也把下面的代码在Application_Error事件Applicaion_Error事件在Global.asax中

var error = Server.GetLastError(); 
var code = (error is HttpException) ? (error as HttpException).GetHttpCode() : 500; 

if (code != 404 || code!=301 ||code!=302) 
{ 
    System.Web.HttpApplication app = (System.Web.HttpApplication)sender; 
    string requestedUrl = app.Request.Path.ToLower(); 
    RequestUrls = requestedUrl; 


    string realUrl = GetRealUrl(requestedUrl.ToLower()); 
    Server.ClearError(); 
    if (!String.IsNullOrEmpty(realUrl)) 
     Response.RedirectPermanent(realUrl,true); 

} 

回答

1

请检查以下代码

var error = Server.GetLastError(); var code =(错误是HttpException)? (错误为HttpException).GetHttpCode():500;

if (code == 404 || code==301 ||code==302) 
{ 
    System.Web.HttpApplication app = (System.Web.HttpApplication)sender; 
    string requestedUrl = app.Request.Path.ToLower(); 
    RequestUrls = requestedUrl; 


    string realUrl = GetRealUrl(requestedUrl.ToLower()); 
    Server.ClearError(); 
    if (!String.IsNullOrEmpty(realUrl)) 
     Response.RedirectPermanent(realUrl,true); 

} 

条件的必须是同等条件下在同等条件

陈述
相关问题