Question

I created simple HttpModule, all what I need is just get is valid Sitecore.Context inside but during processing I see that my Sitecore.Context is some kind of default.

I can get Sitecore user that log in to Sitecore, etc. How to fix it ?

Was it helpful?

Solution

I assume you have a Sitecore Context, but it is null or set to the wrong site or language. You can change the context like this:

// switch to the preferred site    
Sitecore.Context.SetActiveSite("yourSiteName");

// set the preferred database
Sitecore.Context.Database = Sitecore.Configuration.Factory.GetDatabase("master");

// set the preferred language
Language language =  Sitecore.Globalization.Language.Parse("en");
Sitecore.Context.SetLanguage = (language, false);

You probably also want to switch back to the original settings after your processing is done. So it is wise to "save" the original settings in a variable so you can change them back afterwards

OTHER TIPS

Take a look at John West's posts on Sitecore pipelines for some background on how the context is being established.

http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/05/All-About-Pipelines-in-the-Sitecore-ASPNET-CMS.aspx

and

http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/05/Important-Pipelines-in-the-Sitecore-ASPNET-CMS.aspx

The following blog post on creating and running custom pipelines should give you an idea how to implement your own pipeline.

http://adeneys.wordpress.com/2008/08/27/creating-and-running-custom-pipelines-in-sitecore/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top