0

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 ?

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
Arbejdsglæde
  • 13,670
  • 26
  • 78
  • 144

2 Answers2

2

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

Martijn van der Put
  • 4,062
  • 1
  • 18
  • 26
1

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/

Kevin Obee
  • 1,489
  • 1
  • 12
  • 22