Is there any way to work with sessions without locking on ASP.Net MVC site?

爱⌒轻易说出口 提交于 2021-01-27 23:05:41

问题


Is there any way to work with sessions without locking on ASP.Net MVC site ?

Session lock mechanism leads many problems;

When your site slow down little bit, users are start to hit "F5" on the keyboard. When they do this, requests are starting to wait each other. All those requests are hanging on IIS at "RequestAcquireState" state for session module.

If a user made a simultaneous requests this will happen. Because session module in IIS and default session provider (Or generally custom ones) has both lock mechanism.

See:

  • Implementing a Session-State Store Provider
  • Session State Providers

There is locking, because your workflow can be manipulated if you are not carefully designed your process. Been hacked is way big problem for you comparing with performance issues...

But if you designed your process for shared, semi-consistent state store, (Or simply maybe there is no need to use) can we remove locking situation from our way completely?


回答1:


Yes we can remove lock from our way with "UnlockedStateProvider".

It designed for MVC and not implements .Net SessionStateStoreProviderBase because, IIS session module also has locking mechanism.

It is a simple ActionFilterAttribute provide state store for you via HttpContext.

It has also Redis provider so you can use safely in web farm, Azure or AWS.

Please take a look:

  • https://www.nuget.org/packages/UnlockedStateProvider.Redis
  • https://github.com/efaruk/playground/tree/master/UnlockedStateProvider

Note: Developed for advanced usage and not a replacement for any SessionStateProvider...



来源:https://stackoverflow.com/questions/28717430/is-there-any-way-to-work-with-sessions-without-locking-on-asp-net-mvc-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!