naval
naval

Reputation: 1413

Applicaion_Error event in Global.asax

Application_Error is not firing after publishing web site i had also made custom error mode in the web config off and remote only i had also put the following code in the Application_Error Event

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

}

Upvotes: 0

Views: 90

Answers (1)

user1075156
user1075156

Reputation: 26

Please Check the following code

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

}

Conditions their must be equal condition in is stated on equal conditions

Upvotes: 1

Related Questions