I’m trying to use TempData[] in an mvc3 controller and I am running into the following error:
The SessionStateTempDataProvider class requires session state to be
enabled.
The following is set in the webconfig (not my code or project) but…
<modules runAllManagedModulesForAllRequests="true">
<add name="Custom http Module" type="CustomHttpModule" />
</modules>
where CustomHttpModule:
public class CustomHttpModule: IHttpModule
Is this a config setting I can change or possibly define in this CustomHttpModule class?
Make sure that your module implements the
IRequiresSessionStatemarker interface if you want to be able to access the session from an HTTP module:Also in your
web.configmake sure that the session state is enabled:Of course the mode that you are specifying here will depend on setup and requirements. For example if you are running in a web farm storing the session data in memory could be error-prone as each node of the web farm will store its own session and no sharing will be possible. In this case you might need to consider some other modes that enable you to share the session between the nodes of your farm.