views:

623

answers:

2

I am using the System.Web.Routing assembly in a WebForms application. When running the application deployed on win2008/IIS7 I got the following message.

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.

This is only a problem when using a route I have configured. It is not a problem when directly navigating to an aspx page.

EnableSessionState has been turned on in both the web.config and the Page directive. I have added the Session entry to httpmodule of the web.config.

This is not an issue when developing using Visual Studio on my workstation. It is only a problem when trying to run the application under IIS7 on Win 2008.

+1  A: 

I'm having the same issue and I think I know what the problem is.

I'm trying to implement a FileNotFound page under the routing system (something I've yet to figure out is how to both give a FileNotFound page AND give a 404 response in the header)

What I've found, is that for some reason, the pages registered with BuildManager seem to be instanced without session context (the page was not actually requested, just instanced!).

At least that's what it seems to do.


I'm now less sure of my previous assertion. Apparently, requests for images also go through the routing system when they do not exist on physically. This causes an IRouteHandler to be called when the image path matches. I'm pretty sure the session object does not exist when an image is requested, so that may cause the problem when the page that was routed to tries to access it.

SirDemon
A: 

I think that what you are describing is similar to a question that I had.

It may be that your IIS7 is running in a differnt mode nad is more like II6 than 7:

A couple of questions: 1. Is your mapping redirecting your request correctly? 2. When your request is mapped where does it go? 3. If you trace through this page what line of code is generating the error (does it even hit your code)?

Middletone