views:

40

answers:

2

Hi,

My attempts at enabling SessionState are failing :-(

I've added the following page directive to the page:

<%@ Page ... EnableSessionState="True" %>

And to my web.config file, I've added the following:

<system.web>
...
    <sessionState mode="InProc" cookieless="false" />

    <pages enableSessionState="true">
        ...
    </pages>
    <remove name="session" />
    <add name="session" type="System.Web.SessionState.SessionStateModule" />
...
</system.web>

As far as I believe, this should work and I should be able to access the Session object in my code - I'm getting an HTTPException advising me to make sure the above is in my web.config file.

The following line:

<remove name="session" />

was added because without it I get the following error:

The entry 'session' has already been added.

Can anyone assist?

Thanks!

...

+1  A: 

All you need is:

<system.web>
...
    <sessionState mode="InProc" cookieless="false" />
...
</system.web>

Remove the rest from the page and the web.config and it should work. Session is enabled by default.

starskythehutch
Now I'm getting "The entry 'session' has already been added." as an error.
icecreamsoop
you must have other settings which are conflicting. has your machine.config been modified? if you create a new test web app, does session work in that one?
dave thieben
A: 

As I cannot comment yet, I'll post here: does this help you?

http://forums.asp.net/t/1186111.aspx

Tobiasopdenbrouw
Hehe, thanks, fleeced that one already - I'm not convinced the problem lies with the we.config file; a created another page/code-behind that accesses the session object and it works fine.This one has really stumped me. I think it maybe a problem with the VS(or me) has set up the project.
icecreamsoop
Thanks all the same though!
icecreamsoop