Customized error page in Sharepoint

Posted: October 7, 2008 in Errors, EventHandlers, Object Model

In SharePoint there is not any functionality for displaying our customized error page.Like if for data validation in event/item handler we use

properties.ErrorMessage = “Opps… Not allowed”;
properties.Cancel = true;

And validation message displayed in SharePoint error Page which looks error in application.
But with this Context you can use to redirect to any of your custom or any out of the box Page.

SPUtility.Redirect(Url, SPRedirectFlags.Default, current);

Here current is nothing but the HTTPContext object that u create in the constructor of the Event handler class

Advertisements
Comments
  1. Naresh says:

    Hi Chanakya,

    I am struglling to make it work…

    I would like to use this in itemdeleting event reciever for a document library with in sharepoint MOSS 2007.. I have the following code as constructor

    public class ItemDelete:SPItemEventReceiver
    {
    private HttpContext currentContext = null;
    public ItemDelete():base()
    {
    if (null != HttpContext.Current)
    {
    currentContext = HttpContext.Current;
    }
    }
    ..

    and i have used the ccurrentContext in my event as

    public override void ItemDeleting(SPItemEventProperties properties)
    {
    base.ItemDeleting(properties);
    try
    {
    if (–my–condition–)
    {
    SPUtility.Redirect(“http://www.google.com/”, SPRedirectFlags.Default, currentContext);
    }
    }
    catch(Exception){}

    if i run this program the delete event is not triggering at all and redirection is also not happening.. can you please tell me what is that i am missing.

    much appriciate your response.. thanks.

    • chanakya01 says:

      Hi Naresh,

      Your code seems to be perfect.

      Since you are saying the delete event is not triggering check whether your event handler registered properly (Check your feature & element file).

      Also try to debug the code. This way you can make sure your event handler is registered.

      Also check whether your HttpContext object is having some value after the execution of the constructor or still its null.

  2. Naresh says:

    HI Chanakya,

    thanks for your time.. i was unable to get it done by using this method.. after several attempts i end up with an alternative solution, where i added some redirection JavaScript in ERROR.HTM page to redirect to my custom error page based on URL referrer., in that way infact i can avoid the users to see the custom error page too, by adding an another javascript redirection to point back to actual library so in over all it looks like a JavaScript alert on item delete event receiver.

    Thanks again.
    Naresh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s