I built a HttpModule for sharepoint. But when I begin to debug the page request, I notice that the debugging has an strange cycle: 1 - context_PreRequestHandlerExecute() 2- page_PreInit() 3 - Init() . buit don't enter inside the code and step into context_PreRequestHandlerExecute() again and doesn't enter inside the code too, and return into the code of Init ()
I notice that on the debug cursor there's a little warning :"the process of thread has changed since tha last step "
namespace MyAssembly
{
public class Global : IHttpModule
{
public void Init(HttpApplication context)
{
WriteLog.WriteOut("Init ---- INIZO", false);
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
WriteLog.WriteOut("Init ---- FINE", false);
}
public void Dispose()
{
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
WriteLog.WriteOut("context_PreRequestHandlerExecute ---- INIZO", false);
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
page.PreInit += new EventHandler(page_PreInit);
}
WriteLog.WriteOut("context_PreRequestHandlerExecute ---- FINE", false);
}
void page_PreInit(object sender, EventArgs e)
{
WriteLog.WriteOut("page _ PreINT ---- INIZO", false);
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
WriteLog.WriteOut("USING ---- INIZO", false);
Page page = sender as Page;
string pageNo = ConfigurationManager.AppSettings["MasterPageNo"];
if (page != null)
{
WriteLog.WriteOut("\r\n" + "IF --- INIZO", false);
WriteLog.WriteOut("Page non รจ null", false);
page.MasterPageFile = "~masterurl/custom.master";
WriteLog.WriteOut("Valore page.MasterPageFile:"+ page.MasterPageFile,false);
if (pageNo.Equals("1"))
{
WriteLog.WriteOut("Sono dentro a (pageNO = 1)", false);
if (SPContext.Current != null)
{
WriteLog.WriteOut("Sto assgnado a v4_copy.master", false);
SPContext.Current.Web.CustomMasterUrl = "/_catalogs/masterpage/v4_copy.master";
}
}
else if (pageNo.Equals("2"))
{
if (SPContext.Current != null)
{
SPContext.Current.Web.CustomMasterUrl = "/_catalogs/masterpage/v4_copy.master";
}
WriteLog.WriteOut("IF --- FINE" + "\r\n", false);
}
else
{
WriteLog.WriteOut("\r\n" + "ELSE" + "\r\n", false);
WriteLog.WriteOut("page.MasterPageFile = ~masterurl/default.master --- INIZO" + "\r\n", false);
page.MasterPageFile = "~masterurl/default.master";
WriteLog.WriteOut("page.MasterPageFile = ~masterurl/default.master --- FINE" + "\r\n", false);
if (SPContext.Current != null)
{
WriteLog.WriteOut("SPContext.Current.Web.MasterUrl =/_catalogs/masterpage/v4.master --- INIZO" + "\r\n", false);
SPContext.Current.Web.MasterUrl = "/_catalogs/masterpage/v4.master";
WriteLog.WriteOut("SPContext.Current.Web.MasterUrl = /_catalogs/masterpage/v4.master --- FINE" + "\r\n", false);
}
}
}
WriteLog.WriteOut("page _ PreINT ---- FINE", false);
}