yuanrui / blog

Some notes.
http://yuanrui.github.io
3 stars 0 forks source link

Asp.Net Session锁问题 #26

Open yuanrui opened 5 years ago

yuanrui commented 5 years ago

在Mvc项目中使用Session,会导致请求被锁定。慎用Session.

以下是stackoverflow的一些讨论汇总。 Session lock导致请求延迟 https://stackoverflow.com/questions/8349033/storing-anything-in-asp-net-session-causes-500ms-delays

https://weblogs.asp.net/imranbaloch/concurrent-requests-in-asp-net-mvc

https://github.com/aspnet/AspNetSessionState

https://www.c-sharpcorner.com/UploadFile/ff2f08/session-state-behavior-per-action-in-Asp-Net-mvc/ https://devblogs.microsoft.com/aspnet/introducing-the-asp-net-async-sessionstate-module/

https://stackoverflow.com/questions/2326817/asp-net-mvc-and-ajax-concurrent-requests/2327051

其中一个解决办法,使用Heavysoft.LockFreeSessionState.HashTable. 尝试了一下还是有问题,使用TempData和Session容易丢失数据 https://stackoverflow.com/questions/3629709/i-just-discovered-why-all-asp-net-websites-are-slow-and-i-am-trying-to-work-out/25231036

其他的一些方法 https://stackoverflow.com/questions/3666556/a-non-locking-in-process-asp-net-session-state-store

禁用Session的一些讨论 https://stackoverflow.com/questions/1464203/disable-session-state-per-request-in-asp-net-mvc

MSDN 自定义SessionStateModule https://docs.microsoft.com/en-us/dotnet/api/system.web.sessionstate.sessionstateutility?redirectedfrom=MSDN&view=netframework-4.8#snippetGroup