Thursday, April 21, 2011

Override Global.asax in SharePoint

Add your new Global.cs in the sharepoint project. Change Global.asax in your virtual dir so it points to this new class that extends original Sharepoint Global.asax. See the note for the class attached.
Note that the new Global.asax must have full assembly reference in order to search for assembly in GAC. Otherwise it would look for it in virturaldir/bin folder.
In web.config you must have:
under <httpModules>

<add name="Session" type="System.Web.SessionState.SessionStateModule" />

using System;
using System.Web;
namespace CMan.Api.Common{
/**
*  Extension for Global.asax
*  Global.asax in virtual dir for sharepoint application should have following code:
*  <%@ Assembly Name="CMan, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b86b954ddd3528c3"%>
*  <%@ Import Namespace="CMan.Api.Common" %>
*  <%@ Application Language="C#" Inherits="CMan.Api.Common.Global" %>
*/
public partial class Global : Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication
 {
   public Global() { }
   protected void Application_EndRequest(Object sender, EventArgs e)
   {
    //ADD YOUR CODE
   }
   //ADD OTHER GLOBAL.ASAX methods/events you need
Application_AcquireRequestState
Application_AuthenticateRequest
Application_AuthorizeRequest
Application_BeginRequest
Application_Disposed
Application_EndRequest
Application_Error 
Application_PostAcquireRequestState
Application_PostAuthenticateRequest
Application_PostAuthorizeRequest
Application_PostMapRequestHandler
Application_PostReleaseRequestState
Application_PostRequestHandlerExecute
Application_PostResolveRequestCache
Application_PostUpdateRequestCache
Application_PreRequestHandlerExecute
Application_PreSendRequestContent
Application_PreSendRequestHeaders
Application_ReleaseRequestState
Application_ResolveRequestCache
Application_UpdateRequestCache
Application_Init
Application_Start
Application_End
  }
 }
}

2 comments:

  1. what is the value that should be kept in web.config? am seeing yellow screen..

    ReplyDelete
    Replies
    1. I meant the exact value as in your example under .. pls help..

      Delete