views:

33

answers:

1

So i have a couple of custom Http Handlers for different file types. I have implemented the IRequiredSessionState marker, but still recieving context.Session as null?

Do you need to initialize the Session somehow?

+1  A: 

Have you enabled session in your Web.config file? No, you don't need to perform any particular initialization:

<sessionState mode="InProc" />

By the way, the interface name is System.Web.SessionState.IRequiresSessionState, not IRequiredSessionState.

Mehrdad Afshari
Didn't think i need to add extras to the web config. as my session state worked in other sections of the application. Will check it, thanks!
Jan de Jager
is this all? <pages enableSessionState="true">was already set to true?
Jan de Jager
No, you need to enable it with `<sessionState>` element. `<pages>` element applies to ASPX pages only.
Mehrdad Afshari
Great thanks a million... bit of a blond moment..
Jan de Jager
dammit, still nothing.. what am i doing wrong!!!!
Jan de Jager
Are you sure you're testing the correct build of the application and not some older version without `IRequiresSessionState`?
Mehrdad Afshari
yip. Should i not decorate the handlers in the config file with an enableSessionState or something?
Jan de Jager
No. Nothing else is needed. Can you provide some context about how you're currently doing it? Are you messing with HTTP modules too?
Mehrdad Afshari
No just http handler. Is it maybe because i'm posting to it?
Jan de Jager
No, I don't think so. I suggest creating a new empty project and testing a simple handler: `context.Response.Write(context.Session == null);` and altering it incrementally to see what's the issue.
Mehrdad Afshari
ok, thanks for the help. might bug you again later...
Jan de Jager
Eureka! Move the app to IIS from the WebDev thingy, and whalah!
Jan de Jager
I admit WebDev Web server is weird sometimes but I'm sure it does support session state. Anyway, good to see it work.
Mehrdad Afshari
AAAH!!! Dammit, now the production server is not doing anything... session object null again... why would IIS 6 not load the session state? have check and double checked the web.config and iis configs.
Jan de Jager