Asp.net Sessions Getting Crossed / Mixed Up

后端 未结 7 800
北恋
北恋 2020-12-04 20:19

Few weeks ago we had one of our customers contacting us saying that sometimes when he creates an activity it gets created under someone else\'s name!

We did some t

7条回答
  •  孤街浪徒
    2020-12-04 21:01

    Because you all disabled kernel-mode caching, I like to point out some other thinks.

    1) To correctly use the HttpContext.Current.User.Identity.Name, you first need to verify that your user is logedin by using the User.Identity.IsAuthenticated

    2) in this point Session.Add("CurrentUser", currentUser); what are you actual try to save ?

    Now I think that is the problem is on cache. The pages are stored somewhere in between your users and the one mix up with the other. Some of the headers that you can use to your page to avoid the cache on the middle proxy computers.

    Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-2));
    Response.Cache.SetNoStore();
    Response.Cache.SetValidUntilExpires(false);
    Response.Cache.SetCacheability(HttpCacheability.NoCache);                
    Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
    Response.Expires = 0;
    Response.CacheControl = "no-cache";
    Response.AppendHeader("Pragma", "no-cache");
    

    Also I say that if your pages have data that you do not wish to share among your user you need to use Secure HTTPS pages, and set your cookies to be available only on secure pages by adding on web.config

    Also, check if you save your session on SQL server that you scheduled run the clean up routing every 1 minute.

    To been able to find some more information I suggest to store some hidden text on the pages, eg the date-time of the rendered, maybe a the last 4 digit of the userID, and what else you may thing that can help you see if the page come from a cache or not.

提交回复
热议问题