Search code examples
c#asp.netsession-state

session state in asp.net


I'm going to save a variable in session by this:

context.Session["name"] = context.Request.Params["name"];
context.Response.Write(context.Session["name"]);

and the config file is this:

<configuration>
   <system.web>
       <compilation debug="true" targetFramework="4.0" />
       <sessionState cookieless="false" mode="StateServer" timeout="10000"  
           stateConnectionString="tcpip=127.0.0.1:42424">
       </sessionState>
    </system.web>
</configuration>

but I got this error: Object reference not set to an instance of an object.

What is wrong with my code?


Solution

  • Your HttpHandler needs to implement the IRequireSessionState interface, otherwise Session is not available to the handler.