ASP.net session cookie lost or deleted
I have an ASP.NET 2.0 site that stores a user's ID in session to indicate that they are logged in. In some situations, the user doesn't appear to stay logged in. I've been monitoring traffic in Fiddler, and some details I've found:
Any ideas what could cause this?
Edit: the production environment have domains of www.DomainX.com and DomainX.com. There is another known issue with the cookies not being set for both of those domains. It's possible this is related, but I won't be able to test until that fix goes to prod.
You will want to have a look at your session state provider to see if it will work across the two server/instances of the .net application. If they are set for example to inProc then you most definitely will run into this problem as each session will be tied to the thread on which it was created. Instead you want to abstract this to either the asp.net state service which both machines can access or even better you should use a distributed caching solution such as the Microsoft Velocity project which will distribute the sessions across the two machines in case one goes down.
Some other ways to deal with this are to use sticky sessions on the load balancer (not recommended) or move to a cookie-less session which would work but may cause some headaches in your code.
In our business we have a primary and secondary server with a distributed cache behind that so that if one machine goes down the other can take over. This same principle applies to load balancing and once you start having more than one machine or even more than one instance of in the application pool you will have to code for this.
If you use Velocity for session be sure to make sure that the cache that you select for storing your sessions is non-evictable.
I think Middletone is right except: it does not explain why the problem can't be repro'd with Firefox. The load balancer is the no.1 suspect; it'd be good to see if it's got an alibi by taking all but one of the app servers offline (if feasible, and during a time when it can handle the load) and see if the problem still exists. If so, it's not the load balancer and you can start looking somewhere else. If not, it's the load balancer.
BTW: Sticky sessions are bad because the sessions that are on it are not protected by redundancy. In addition, the load balancer cannot distribute to the least-loaded server at a certain point in time, it can only decide at the start of a session and then keep the user where he/she is.
If it turns out you've got a load balancer problem here, the first thing I'd do is turn on session stickyness, and then maybe look for another solution with the soothing backgroung of a working production environment.
Shoot, I must have lost my cookie and ability to reply and edit...
I did explore the load balancer as the issue a little bit by modifying my hosts file to point directly to the IPs of each of the web servers, and that didn't have any effect. I think the client's IT staff is going to balk at asking to shut off load balancing.
We do have a separate state server running, and it's the same one that's been used for a few years on other sites hosted by the same servers. Not necessarily without problems, but without a problem like this.
As a band-aid, I'm currently testing other persistance mechanisms...
链接地址: http://www.djcxy.com/p/44564.html下一篇: ASP.net会话cookie丢失或删除