Application_Error在发布网站后没有触发我已经在web配置中关闭了自定义错误模式而且只有远程我也将以下代码放在Application_Error事件中
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);
}
答案 0 :(得分: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);
}
在相同的条件下,条件必须是相同的条件