views:

45

answers:

2

I need unique session id but each it's new unless you write something in it. The fix looks like this Session["stubkey"] = "fsdufhusd" in page load method. It's pretty odd to me. Is there any way to init session or probably I do something wrong with configs?

thanks in advance.

+2  A: 

The SessionID documentation recommends the same work-around you're using:

When using cookie-based session state, ASP.NET does not allocate storage for session data until the Session object is used. As a result, a new session ID is generated for each page request until the session object is accessed. If your application requires a static session ID for the entire session, you can either implement the Session_Start method in the application's Global.asax file and store data in the Session object to fix the session ID, or you can use code in another part of your application to explicitly store data in the Session object.

Jeff Sternal
A: 

You don't need to initialize the session on page_load. You can initialize the session on Global.asax like this

protected void Session_Start(Object sender, EventArgs e) 
{
    Session["init"] = 0;
}
Claudio Redi