Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Access to EPiServer API from global.asax

Vote:
 

Hi,

Having tried to access the EPiServer API from global.asax and failed I was wondering how I might go about adding some code that will be executed every time asp.net creates a new session (Session_Start in global.asax).

If that is impossible then how can I hook up some code that is executed on every request (as early as possible in the pipeline, similar to Application_BeginRequest) and has access to the episerver api.

Thanks.

#147052
Apr 05, 2016 12:29
Vote:
 

Hi

Could you use HttpApplication.BeginRequest event?

    [ModuleDependency(typeof(InitializationModule))]
    public class SampleInitializer : IInitializableHttpModule
    {
        public void InitializeHttpEvents(HttpApplication application)
        {
            application.BeginRequest += ApplicationOnBeginRequest;
        }
        
        private void ApplicationOnBeginRequest(object sender, EventArgs eventArgs)
        {
            // You can access episerver APIs with ServiceLocator            
            var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
            
            // TODO your code here       
            throw new NotImplementedException();
        }

        public void Initialize(InitializationEngine context)
        {
        }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }
#147096
Edited, Apr 06, 2016 0:44
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.