Monday, 9 January 2017

Set Custom error page for all Application label error and error code also

//  IN Global.asax Under Application_Error

void Application_Error(object sender, EventArgs e)
    {
        //////////// Code that runs when an unhandled error occurs

        //Response.Redirect("~/Error Page Not Found");

        Exception ex = Server.GetLastError();
        Application["TheException"] = ex; //store the error for later
        Server.ClearError(); //clear the error so we can continue onwards
        Response.Redirect("~/Error Page Not Found"); //direct user to error page

    }



// IN web.config file Under

  <system.web>
<!--<customErrors mode="Off"></customErrors>-->
<customErrors mode="RemoteOnly" defaultRedirect="~/Error Page Not Found"></customErrors>

  </system.web>

<system.webServer>

    <httpErrors errorMode="Custom" defaultResponseMode="Redirect">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="~/Error Page Not Found"
       responseMode="Redirect" />
    </httpErrors>

    <validation validateIntegratedModeConfiguration="false"/>

</system.webServer>

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...