Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Global.asax中的应用程序错误事件_Asp.net - Fatal编程技术网

Asp.net Global.asax中的应用程序错误事件

Asp.net Global.asax中的应用程序错误事件,asp.net,Asp.net,发布网站后,应用程序_错误未触发。我还关闭了web配置中的自定义错误模式,仅远程。我还将以下代码放入了应用程序_错误事件中 var error = Server.GetLastError(); var code = (error is HttpException) ? (error as HttpException).GetHttpCode() : 500; if (code != 404 || code!=301 ||code!=302 ) { System.Web.HttpAppl

发布网站后,应用程序_错误未触发。我还关闭了web配置中的自定义错误模式,仅远程。我还将以下代码放入了应用程序_错误事件中

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);

}

请检查以下代码

var error=Server.GetLastError(); var代码=(错误为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);

}