Applicaion_Error event in Global.asax
<p>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</p>

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

}
</code></pre>
