Click here to Skip to main content
15,884,237 members
Articles / Web Development / ASP.NET

Handling Error Centrally in a SharePoint Application

Rate me:
Please Sign up or sign in to vote.
4.21/5 (11 votes)
20 May 2008CPOL4 min read 84.9K   596   22  
An article on handling errors centrally in a SharePoint application, using IHttpModule.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyErrorHandler.aspx.cs" Inherits="MyErrorHandler" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Error Page</title>
    <style type="text/css"><!--
    *{
    font-family:Verdana;font-size:14px;
    }
.div_getinfo
{
  clear:both;
  margin-top:4px;  
  margin-bottom:4px;  

}
.div_getinfo span
{  
  padding-right:10px; 
  vertical-align:top;
  
  /*
  margine-right:10ppx;

    
     padding-left:100px; 
    width:198px
      */
}
.save{
   behavior:url(#default#savehistory);}
a.dsphead{
   text-decoration:none;
   margin-left:2px;
   font-size:14px;
   
   ;}
a.dsphead:hover{
   text-decoration:underline;}
a.dsphead span.dspchar{
   font-family:monospace;
   font-weight:normal;}
.dspcont{
   display:none;
   margin-left:20px;}
//--></style>

    <script type="text/javascript"><!--
function dsp(loc){
   if(document.getElementById){
      var foc=loc.firstChild;
      foc=loc.firstChild.innerHTML?
         loc.firstChild:
         loc.firstChild.nextSibling;
      foc.innerHTML=foc.innerHTML=='+'?'-':'+';
      foc=loc.parentNode.nextSibling.style?
         loc.parentNode.nextSibling:
         loc.parentNode.nextSibling.nextSibling;
      foc.style.display=foc.style.display=='block'?'none':'block';}}  

if(!document.getElementById)
   document.write('<style type="text/css"><!--\n'+
      '.dspcont{display:block;}\n'+
      '//--></style>');
//--></script>

</head>
<body style="text-align: center;">
    <form id="form1" runat="server">
        <div style="width: 800px; text-align: left; margin-top: 30px">
            <asp:Label ID="Label1" runat="server" Width="140px">Title:</asp:Label>
            <asp:Label ID="Label2" runat="server">An unexpected error has occurred.</asp:Label><br />
            <asp:Label ID="Label5" runat="server" Width="140px">Error Code:</asp:Label>
            <asp:Label ID="uxErrorCode" runat="server"></asp:Label><br />
            <asp:Label ID="Label3" runat="server" Width="140px">Description:</asp:Label>
            <asp:Label ID="uxErrorMessage" runat="server"></asp:Label><br />
            <div class="save">
                <h1>
                    <a href="javascript:void(0)" class="dsphead" onclick="dsp(this)"><span class="dspchar">
                        +</span>StackTrace</a></h1>
                <div class="dspcont">
                    <asp:Label ID="uxStackTrace" runat="server">No information available!</asp:Label></div>
            </div>
            <div class="div_getinfo" style="margin-top: 20px">
                <div style="display: inline; float: left">
                    <asp:Label ID="Label7" runat="server" Width="140px">ActionDescription:</asp:Label>
                </div>
                <div style="display: inline; float: left">
                    <asp:Label ID="Label8" runat="server">Please contact support@Anupam Ranku<br /> supply the Error-Code.</asp:Label>
                </div>
            </div>
            <div style="clear: both; display: block; margin-top: 20px;">
                <a href="JavaScript:void(0);" onclick="javascript:history.back();">Go back to site</a>
            </div>
        </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Gen-i, Australia
Australia Australia
Expertise area: ASP.NET, C#, Microsoft Office SharePoint 2010 & 2007, Web Service, Windows-based Applications etc.

Blog: http://mydevdiary.blogspot.com/

Comments and Discussions