Sharepoint Master Pages and Session State

南笙酒味 提交于 2019-12-12 22:32:31

问题


I’m using Heather Solomon’s minimal publishing master page, I’ve got a simple feature with an apsx page and a code behind file that does this

public class SSInformPage : Page
{
    protected Literal Literal1;

    protected override void OnLoad(EventArgs e)
    {
        //base.OnLoad(e);
        try
        {                
            HttpContext.Current.Session["Name"] = "Mr Ben";
            Literal1.Text = string.Format("{0} {1}", HttpContext.Current.Session["Name"].ToString(), Session.SessionID);
        }
        catch (Exception ex)
        {
            Literal1.Text = string.Format(ex.Message.ToString());
        }
    }

}

When this page loads in the browser I get the following error

Object reference not set to an instance of an object.

Yet if I switch to an out of the box master page (e.g. Black Vertical) the code works! I get the expected output of “Mr Ben {session ID}”

I’ve even created a new blank master page and copied the entire contents of the Black Vertical master page into it. I set the site to this new master page, I load the page expecting everything to work and receive the ‘Object reference…’ error. How does that work? It’s exactly the same master page yet the code only works if it’s an OOTB version.

I've enabled session state in central admin, the web.config file and the assembly is deployed to the GAC.

Update From a suggestion on another forum it seems to be a trust issue, i was mistaken in thinking the solution deploys to the GAC, it was actually deploying to the Bin folder. I've tried to reset this but can't seem to get WSPBuilder to deploy to the solution to the GAC, although i've managed to get it to stop deploying to the web application's bin folder.

Does anyone know how to get a soltution to deploy to the GAC folder? this is my stsadm command

stsadm -o deploysolution -name Test.SessionState.Solution.wsp -immediate -url http://example -allowGacDeployment -allowCasPolicies -force

Udpate 2 No it's not a trust issue, I re-created my solution and ensures it deploys to the GAC. If I open a OOTB master page in sharepoint designer and click the save button it's will 'customise' the page. As soon as I do this my code stops working, if I then reset the master page back to the site definition my code starts working again!

I have a soltion file is anyone want to install this to see the behaviour.


回答1:


I think i found the reason, it seems if a custom master page is wrapped in a solution this problem doesn't occur (most of the time).

Here's an article listing the issue and possible work arounds

https://stackoverflow.com/questions/981836/perform-find-and-replace-in-visual-studio-build-events




回答2:


I can't help with your specific error and Heather's master page should work fine, however I'm concerned that you mention enabling session state in the web.config file. The correct place is in SharePoint Central Administration using the instructions here.

This is because SharePoint provides its own session manager as session has to be shared across multiple WFEs. If you really want to do this the standard ASP.NET way, use Eric Kraus' instructions. Not sure how supported this is however or what side effects it causes.

Try one of these alternatives and let us know how it goes. Hopefully the error goes away!



来源:https://stackoverflow.com/questions/1109155/sharepoint-master-pages-and-session-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!