views:

905

answers:

2

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.

A: 

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!

Alex Angas
sorry forgot to mention that I enabled session state in central admin. If you look at point 5, that's where it mentions modifying the web config. thanks for replying though!
Rob
I've just checked and I can confirm that session information is being stored in the 'ASPStateTempSessions' table of the shared service provider.
Rob
Hmmm... I'll keep thinking and let you know if I come up with anything else. Please add the answer if you work it out before any of us do!
Alex Angas
will do, it's certaintly got me stumped!
Rob
+1  A: 

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

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

Rob