Asp.net Sessions Getting Crossed / Mixed Up

后端 未结 7 785
北恋
北恋 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 20:52

    Since this seems to fall into the extremely arcane problem territory, maybe it's time for a leap.

    You could stop using the ASP.NET session to store your identifiers altogether.

    You have a bunch of options of where you could stick this information instead. You could choose to encrypt it into the Forms Authentication ticket's UserData property (I've done this before in production, it works great for storing a key(s), csv of roles, or even small json objects). Past the forms auth ticket, you could write the information directly as your own cookie. You could also bypass cookies altogether.

    If you choose to bypass the cookies, you're basically entering into similar territory of the cookieless ASP.NET sessions. You have a couple of options, you could make the user identifier be apart of every single url as a query parameter. Another option would be to create a HttpModule that would add a hidden form input into every page response that contains the logged in user's identifier.

    If you go down the cookieless path absolutely make sure it's not possible to use your site as HTTP and every single request is HTTPS. Even more especially if you use the query parameter method.

提交回复
热议问题