none
Custom Application.master RRS feed

  • Question

  • Hi,

     I have a custommaster page applied to all sites,I applied the custom masterpage to Layoutpages using HTTPmodule.But when i open the SearchKeywords page in setting,I am getting an error

    Trying to use an SPWeb object that has been closed or disposed and is no longer valid.   at Microsoft.SharePoint.Portal.Search.Admin.Pages.SearchAdminPageBase.ErrorHandler(Object sender, EventArgs e)
       at System.Web.UI.TemplateControl.OnError(EventArgs e)
       at System.Web.UI.Page.HandleError(Exception e)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at ASP._layouts_listkeywords_aspx.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    None on the layoutpages are showing this error,they are all working fine.

    Thanks,

    Sree

    • Edited by sreemouni Thursday, April 22, 2010 6:08 PM unanswered
    Friday, April 9, 2010 9:32 PM

Answers

  • Instead of taking a copy of default.master, try taking a copy of application.master and modify that one.

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\application.master

    Paul.

     

    • Marked as answer by sreemouni Tuesday, May 11, 2010 9:49 PM
    Thursday, April 22, 2010 7:27 PM

All replies

  • If you disable the HttpModule, do the pages work ok?

    Maybe post the module code so we can see what the issue might be.

    Friday, April 9, 2010 9:54 PM
  • dont close SPWeb in your custom http module code, which happens if you use using clause with SPWeb.

    Friday, April 9, 2010 10:15 PM
  • Hi Here is my code for httpmodule, Configureapplicationpagemaster is the property added to the spweb propeties.Which is set to true in feature activation of masterpage

    class

     

    MasterPageManager

    {

     

    public static void ConfigureApplicationPageMaster(bool ApplyApplicationPageMaster)

    {

     

    SPWeb TopLevelSite = SPContext.Current.Site.RootWeb;

     

    if (ApplyApplicationPageMaster)

    {

    TopLevelSite.Properties[

    "UseCustomApplicationPageMaster"] = "True";

    }

     

    else

    {

    TopLevelSite.Properties[

    "UseCustomApplicationPageMaster"] = "False";

    }

    TopLevelSite.Properties.Update();

    }

    }

    (the below line is called in the featureactivation)

    MasterPageManager.ConfigureApplicationPageMaster(

    true)

    (code for httpmodule)

    namespace

     

    MasterPage

    {

     

    class MasterPageHttpModule : IHttpModule

    {

     

    public void Init(HttpApplication context)

    {

    context.PreRequestHandlerExecute

    +=

    new EventHandler(context_PreRequestHandlerExecute);

    }

     

    void context_PreRequestHandlerExecute(object sender, EventArgs e)

    {

     

    Page page = HttpContext.Current.CurrentHandler as Page;

     

    if (page != null)

    {

     

    // register handler for PreInit event

    page.PreInit +=

    new EventHandler(page_PreInit);

    }

    }

     

    void page_PreInit(object sender, EventArgs e)

    {

     

    Page page = sender as Page;

     

    if ((page != null) &&

    (page.MasterPageFile !=

    null) &&

    (page.Request.Url.AbsolutePath.Contains(

    "_layouts")) &&

    (

    SPContext.Current != null))

    {

     

    // inspect UseCustomApplicationPageMaster property

     

    SPWeb site = SPContext.Current.Site.RootWeb;

     

    string UseCustomApplicationPageMaster =

    site.Properties[

    "UseCustomApplicationPageMaster"];

     

    if ((!string.IsNullOrEmpty(UseCustomApplicationPageMaster)) &&

    (UseCustomApplicationPageMaster.Equals(

    "True")))

    {

     

    // now replace application.master with customized version

     

    if (page.MasterPageFile.Contains("application.master"))

    {

    page.MasterPageFile =

    "/_layouts/CEBMasterPage.master";

    }

    }

    }

    }

     

    public void Dispose() { }

    }

    Tuesday, April 13, 2010 8:53 PM
  • Hi Sree,

    Your code looks ok and seems to work fine when I tried it out myself, even on the Search Keywords page. I did some reformatting for readability here.

    public class MasterPageManager
    {
    
        public static void ConfigureApplicationPageMaster(bool ApplyApplicationPageMaster)
        {
            SPWeb TopLevelSite = SPContext.Current.Site.RootWeb;
            if (ApplyApplicationPageMaster)
            {
                TopLevelSite.Properties["UseCustomApplicationPageMaster"] = "True";
            }
            else
            {
                TopLevelSite.Properties["UseCustomApplicationPageMaster"] = "False";
            }
            TopLevelSite.Properties.Update();
        }
    }
    
    //(the below line is called in the featureactivation)
    //MasterPageManager.ConfigureApplicationPageMaster(true)
    //(code for httpmodule)
    
    class MasterPageHttpModule : IHttpModule
    {
    
        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
        }
    
        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            Page page = HttpContext.Current.CurrentHandler as Page;
    
            if (page != null)
            {
                // register handler for PreInit event
                page.PreInit += new EventHandler(page_PreInit);
            }
        }
    
        void page_PreInit(object sender, EventArgs e)
        {
            Page page = sender as Page;
            if ((page != null) 
                && (page.MasterPageFile != null) 
                && (page.Request.Url.AbsolutePath.Contains("_layouts")) 
                && (SPContext.Current != null))
            {
                // inspect UseCustomApplicationPageMaster property
                SPWeb site = SPContext.Current.Site.RootWeb;
                string UseCustomApplicationPageMaster = site.Properties["UseCustomApplicationPageMaster"];
    
                if ((!string.IsNullOrEmpty(UseCustomApplicationPageMaster)) 
                    && (UseCustomApplicationPageMaster.Equals("True")))
                {
                    // now replace application.master with customized version
                    if (page.MasterPageFile.Contains("application.master"))
                    {
                        page.MasterPageFile = "/_layouts/application2.master";
                    }
                }
            }
        }
    
        public void Dispose() { }
    }

    I'm not quite convinced the HttpModule is the problem; so, if you disable your HttpModule, does the Search Keywords page work?

    Is there any chance there has been some other customization made to the search keywords page?

    Paul.

     

    Tuesday, April 13, 2010 10:50 PM
  • This error usual occurs when you use SPContext and dispose it improperly.

    Try to make sure you are using SPWeb when it is in current context.

    or try to use SPWeb in different way instead of SPWeb site = SPContext.Current.Site.RootWeb;


    백상하 - http://blog.naver.com/lightyea/
    • Marked as answer by Aaron Han - MSFT Friday, April 16, 2010 6:25 AM
    • Unmarked as answer by sreemouni Thursday, April 22, 2010 6:02 PM
    Tuesday, April 13, 2010 11:01 PM
  • I am really not sure what exactly is causing the problem.But when i browse for the first time the page search keyword is working.When i refresh i see this error,When i debug the code the current handler  is sphttphandler instead of aspx_listkeywords.The page is null.When i remove my httphandler the search keywords page is working fine.I didnt make any customizations to search keywords page.
    • Edited by sreemouni Sunday, April 18, 2010 2:33 PM missed one line
    Sunday, April 18, 2010 2:29 PM
  • Ok the reason why your current handler might be sphttphandler is because the breakpoint may have hit on a different http request, and not the request for your page (for example a css file or image). Try setting your breakpoint only inside the pre_init event handler.

    The next thing I would do is leave your HttpModule enabled, but comment out the line that does the change for the MasterPage. See if that makes a difference. If you find that the HttpModule runs ok without changing the master page, then the issue is more likely to be with your custom master page.

    BTW, if your question hasn't been answered, maybe unmark the answer above so that more people will look at the post and give some ideas.

    Monday, April 19, 2010 1:31 PM
  • Ya you are right,The httpmodule is working.The problem is with my master page.I dont know what is wrong in my master page,I just took copy of  default master and added two place holders to the  asp hidden panel in the master page .All the layout pages are working fine except listkeywords.Do i need to add any thing  to the master page to work or remove from the master page,Please advice.

    <asp:Panel ID ="layoutplaceholders" runat="server" Visible="false"> <asp:ContentPlaceHolder id="PlaceHolderPageDescriptionRowAttr" runat="server"/> <asp:ContentPlaceHolder id="PlaceHolderPageDescriptionRowAttr2" runat="server"/> </asp:Panel>
    Thursday, April 22, 2010 6:16 PM
  • Instead of taking a copy of default.master, try taking a copy of application.master and modify that one.

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\application.master

    Paul.

     

    • Marked as answer by sreemouni Tuesday, May 11, 2010 9:49 PM
    Thursday, April 22, 2010 7:27 PM
  • Hi,

    I tried changing the copy of application.master.It worked with out any problems.

    Thanks,

    Sreemouni.

     

    Tuesday, May 11, 2010 10:03 PM