Handling custom HTTP error messages on IIS 7 by SharePoint 2010

HTTP errors are returned to the client when something goes wrong on the server. Error status codes are returned if the requested file isn't found (404), or due to coding errors in the web page (500), and due to temporary issues such as failed database connections (500). The most common errors are 404 (file not found) and 500 (application) errors.

Check the following list of IIS errors

  • 400 Error (bad request)
  • 401 Error (unauthorized)
  • 403 Error (forbidden)
  • 404 Error (not found)
  • 500 Error (internal server error)

How to Custom HTTP Errors?

To implement SharePoint support of the custom HTTP error you have to editing in WebConfig file by adding the below section inside <system.webServer> tag and then you can replace "/Pages/404.aspx" with your own dynamic page.

<httpErrors errorMode="Custom" existingResponse="Auto">
     <remove statusCode="404" subStatusCode="-1" />
           <error statusCode="404" prefixLanguageFilePath="" path="/Pages/404.aspx" responseMode="ExecuteURL" />

Actually the important part in the above snippet code is in <httpErrors errorMode="Custom" existingResponse="Auto"> because if you are working in SharePoint Config file you have to add to the httpErrors element setting error mode to custom and this will inform IIS to you out custom page.  


This configuration is just supported in newest versions of IIS starting from IIS7

Find Controls in an ASP.NET Page with a MasterPage

5. September 2011 01:07 by Mahmoud Farhat in ASP.NET, C#  //  Tags:   //   Comments (0)

If you are seeking to access control in a master page or aspx page files you have to use FindControl method.

The following code examples shows how to use the FindControl method to get a reference to controls so when using MasterPage file you will find controls rendered with prefix such as “ctl00$<ContentPlaceHolderID>$<NameYouGaveToControl>” according to their place in the page hierarchy so you must get reference to the ContentPlaceHolder first and then use FindControl mehtod to locate the control.


ContentPlaceHolder mpContentPlaceHolder = 
if (mpContentPlaceHolder != null)
     Button mpbtnSave = (Button)mpContentPlaceHolder.FindControl("btnSave");

 Gets a reference to a Button control that not in a "ContentPlaceHolder".


Button mpbtnSave = (Button) Master.FindControl("btnSave");

Gets a reference to a Button control that is in aspx page and not in a MasterPage.


Button mpbtnSave = (Button) Page.FindControl("btnSave");

Listbox - Change Item's Color

4. September 2011 15:32 by Mahmoud Farhat in ASP.NET, C#  //  Tags:   //   Comments (0)

If you have two collection lists one of them for parent (Main Category) and other one for child (Sub Category) and you want to display both of them in one listbox but you want the parent item take back color different than the child, the below example code is showing how to do this.  
//loop for parent collection list
foreach (var parentItem in objParentCollectionList)
   //Set all back color items with blue
   listBox1.BackColor = Color.Blue;
   //inset parent items in listbox control
   listBox1.Items.Add(new ListItem(mainItem.Name, mainItem.ID.ToString()));
   //Get all childs by parent ID
   objChildCollectionList = GetChildList(mainItem.ID);
   if (objChildCollectionList != null)
       //loop for child collection list
       foreach (var childItem in objChildCollectionList)
           ListItem listItem = new ListItem(childItem.Name, childItem.ID.ToString());
           //change back color foe each child item
           listItem.Attributes.Add("style""background-color: Azure");
           //inset child items in listbox control
listbox1.BackColor = Color.Blue; it will effect on all listbox items not on specific item