views:

78

answers:

2

Hi Experts, I am implementing the Ecommerce projects, where I need to static SessionID, is there any way to maintain the SessionID in the Entire Application.Explanation of my question is here http://stackoverflow.com/questions/2467644/session-sessionid-in-asp-net but How can I implement this approach.

A: 

Reading the other post you mention, it sounds like either Session was not being used, and so a new Session ID was generated on each request. To fix this, just store something (anything) in the session on the first request to make sure it sticks.

Session["something"] = "anything";

Or, it could be that the user did not allow cookies, which would also cause a new session on each request. So, your users need to allow cookies.

Or you could use cookie-less session.

The other post explains it pretty well, I think.

Ray
+2  A: 

Now I understand your point

you have to do something like this on the Global.asax file

protected void Session_Start(Object sender, EventArgs e)
{
  Session["DummyData"] = "dummy";
}

Adding any value to the Session object at the very first moment after created, you avoids to get different SessionIDs because the Session object wasn't accessed yet.

EDIT
Anyway checking your last comment I don't see that this is something that is affecting your development in some way. Probably you're over thinking on this. If you just need to avoid users to buy more than X products, you don't care about this problem. When the first product is added to the session, the same SessionID will be used in successive requests, until it expires.

Claudio Redi
+1: I deleted my post after getting a better understanding of the OP's question. It seems more an issue of establishing the session rather than the session id changing because of a web-farm.
CAbbott
what is the best way to implement,user can not buy more than 5(this is dynamic value) product in a Session.
Vijjendra
@Claudio: Redi, I am using Collection<Product>, but theirs are any other type of conditions,like user did not add more than 2 a product(productId=2), but he can add 4 another product(productId=7) but total product should not be more than 5, something like that.
Vijjendra