Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
         }
share|improve this question
4  
No help from me, do a bit research, that is a third question from you regarding same HttpModule lol –  Shkipper Nov 22 '12 at 11:23
1  
I agree with @Shkipper, and you know you should accept an answer if it suffices your requirement, it is nice to let other people know that their solution worked for you, you have 0% accept rate presently –  Diptarag Nov 22 '12 at 13:49
    
Moreso, what's the actual question? The 'question' title refers to Pages, yet you post code about a Module. –  James Love Nov 22 '12 at 19:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.