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

Hi I built a Http Module that change Sharepoint MasterPage based on if the user logged in is a Owner/adminstrator. It Works good! But when I try to change the user to test the module, when a click on menu ""log in with different user" the page crash!

my code:

namespace MyAssembly
{
    public class Global : IHttpModule
    {

        private static String MasterAdmin = String.Empty;
        private static String appPath = null;
        private static bool isPageNotNull = false;
        private static bool isAdmin = false;
        private List<SPGroup> _groupsListCollection = new List<SPGroup>();



        public void Init(HttpApplication context)
        {

            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);

        }
        public void Dispose()
        {

        }

        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {

            Page page = HttpContext.Current.CurrentHandler as Page;
            if (page != null)
            {
                page.PreInit += new EventHandler(page_PreInit);
            }

        }


        void page_PreInit(object sender, EventArgs e)
        {




            Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate() //Con privilegi di amministratore --> Questo metodo รจ accessibile a tutti!
              {
                  using (SPSite site = new SPSite(SPContext.Current.Site.Url)) //Mi connetto alla Site Collection
                  {
                      using (SPWeb scWeb = site.OpenWeb()) 
                      {
                          if (SPContext.Current.Web.AssociatedOwnerGroup.ContainsCurrentUser)
                          {
                               isAdmin = true;
                          }

                          else if(SPContext.Current.Web.CurrentUser.IsSiteAdmin)
                          {
                              isAdmin = true;
                          }

                          Page page = sender as Page;
                          if (page != null)
                          {
                              isPageNotNull = true;
                          }



                          if (isPageNotNull)
                          {


                          System.Configuration.Configuration rootWebConfig =System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(page.Request.ApplicationPath);
                          if (rootWebConfig.AppSettings.Settings.Count > 0)
                          {

                              System.Configuration.KeyValueConfigurationElement adminSetting = rootWebConfig.AppSettings.Settings["Thun_MasterPage_Admin"];


                              if (adminSetting != null)
                              {
                                  MasterAdmin = adminSetting.Value;
                              }

                          }
                          }

                          if (page != null)
                          {



                              if (isAdmin && !(String.IsNullOrEmpty(MasterAdmin)))
                              {

                                  page.MasterPageFile = "~masterurl/custom.master";


                                  if (SPContext.Current != null)
                                  {

                                      SPContext.Current.Web.CustomMasterUrl = MasterAdmin;

                                  }
                              }

                          }
                          else
                          {

                          }



                      }

                  }
              }
                                      );

        }
    }
}

I don't have the specific error. Because I get the general error. I tried to fix this but with no success!

enter image description here

share|improve this question
    
Try setting CustomErrors to "Off" in your web.config. Then, you can get a detailed exception. serverintellect.com/support/programming/custom-errors.aspx –  Kit Menke Nov 27 '12 at 16:46
    
Already done. But it sends me the same error! –  Bruno Ferreira Nov 27 '12 at 17:04
    
Woops, also find the SafeMode node and turn CallStack to "True". –  Kit Menke Nov 27 '12 at 17:38
    
Is already true! I posted my web.config code. Without many references of course. Maybe you can show me my error! –  Bruno Ferreira Nov 27 '12 at 18:11
    
Please also post any relevant output from the ULS logs. –  James Love Nov 27 '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.