How to display Custom Error Page
Most of the time we don’t want to display WSS default Error Page, as it looks scary. Instead we want to display our custom error page. Displaying custom error page when exception occurs provide lots of benefits like we can create error log for further debugging. Process of displaying custom error page is very simple and involve following steps:
WSS Utility to Transfer Control(Redirect) to WSS default Error Page
If you want to display WSS default error page from your custom code then there is a function available in SPUtility class. You can call this funtion and pass message to be displayed as an argument.
For more information about go to MSDN
- Backup the web.config.
- Open the web.config in notepad and change ( for Sharepoint, if you are not doing it for Sharepoint then skip this step)
<SafeMode MaxControls="200" CallStack="false"
to
<SafeMode MaxControls="200" CallStack="true"
- You will also need to change the CustomErrors mode to "Off"
<customErrors mode="Off"/>
- Save changes.
- Backup the Global.asax.
- Open the Global.asax in notepad or any Editor and insert this code
<script runat="server">
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Response.Redirect("<Url of Custom Error Page>");
}
</script>
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Response.Redirect("<Url of Custom Error Page>");
}
</script>
- Save changes.
WSS Utility to Transfer Control(Redirect) to WSS default Error Page
If you want to display WSS default error page from your custom code then there is a function available in SPUtility class. You can call this funtion and pass message to be displayed as an argument.
// Transfer to error Page
SPUtility.TransferToErrorPage(string Message)
SPUtility.TransferToErrorPage(string Message)
For more information about go to MSDN
Comments
Post a Comment