打印预览中的 ASP.NET 页面后台 sleep, 会卡住其它网络请求的解决办法
2021-02-08 01:19
标签:com data nbsp move 网络 activator end logger clu 1) Web.config中 2)增加一个class:LocklessInProcSessionStateStore using System; 打印预览中的 ASP.NET 页面后台 sleep, 会卡住其它网络请求的解决办法 标签:com data nbsp move 网络 activator end logger clu 原文地址:https://www.cnblogs.com/wkh-lhw/p/13085704.html
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Collections.Specialized;
using log4net;
namespace web_admin.code.controller
{
///
/// 不锁定的 session ,复制自 When a Single ASP.NET Client makes Concurrent Requests for Writeable Session Variables
/// https://www.red-gate.com/simple-talk/dotnet/asp-net/single-asp-net-client-makes-concurrent-requests-writeable-session-variables/
///
///
public class LocklessInProcSessionStateStore : SessionStateStoreProviderBase
{
private SessionStateStoreProviderBase _store;
public override void Initialize(string name, NameValueCollection config)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("Initialize(string name, NameValueCollection config) begin:" + name);
base.Initialize(name, config);
var storeType = typeof(SessionStateStoreProviderBase).Assembly.GetType("System.Web.SessionState.InProcSessionStateStore");
_store = (SessionStateStoreProviderBase)Activator.CreateInstance(storeType);
_store.Initialize(name, config);
log.Debug("Initialize(string name, NameValueCollection config) end:" + name);
}
public override void Dispose()
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("Dispose begin");
_store.Dispose();
}
public override bool SetItemExpireCallback(SessionStateItemExpireCallback expireCallback)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("SetItemExpireCallback begin");
return _store.SetItemExpireCallback(expireCallback);
}
public override void InitializeRequest(HttpContext context)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("InitializeRequest begin");
_store.InitializeRequest(context);
}
public override SessionStateStoreData GetItem(HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId,
out SessionStateActions actions)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("GetItem begin");
var returnValue = _store.GetItem(context, id, out locked, out lockAge, out lockId, out actions);
if (returnValue == null && lockId != null)
{
_store.ReleaseItemExclusive(context, id, lockId);
returnValue = _store.GetItem(context, id, out locked, out lockAge, out lockId, out actions);
}
return returnValue;
}
public override SessionStateStoreData GetItemExclusive(HttpContext context, string id, out bool locked, out TimeSpan lockAge,
out object lockId, out SessionStateActions actions)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("GetItemExclusive begin");
var returnValue = _store.GetItemExclusive(context, id, out locked, out lockAge, out lockId, out actions);
if (returnValue == null && lockId != null)
{
_store.ReleaseItemExclusive(context, id, lockId);
returnValue = _store.GetItemExclusive(context, id, out locked, out lockAge, out lockId, out actions);
}
return returnValue;
}
public override void ReleaseItemExclusive(HttpContext context, string id, object lockId)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("ReleaseItemExclusive begin");
_store.ReleaseItemExclusive(context, id, lockId);
}
public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("SetAndReleaseItemExclusive begin");
_store.SetAndReleaseItemExclusive(context, id, item, lockId, newItem);
}
public override void RemoveItem(HttpContext context, string id, object lockId, SessionStateStoreData item)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("RemoveItem begin");
_store.RemoveItem(context, id, lockId, item);
}
public override void ResetItemTimeout(HttpContext context, string id)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("ResetItemTimeout begin");
_store.ResetItemTimeout(context, id);
}
public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("CreateNewStoreData begin");
return _store.CreateNewStoreData(context, timeout);
}
public override void CreateUninitializedItem(HttpContext context, string id, int timeout)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("CreateUninitializedItem begin");
_store.CreateUninitializedItem(context, id, timeout);
}
public override void EndRequest(HttpContext context)
{
ILog log = LogManager.GetLogger(typeof(LocklessInProcSessionStateStore));
log.Debug("EndRequest begin");
_store.EndRequest(context);
}
}
}
文章标题:打印预览中的 ASP.NET 页面后台 sleep, 会卡住其它网络请求的解决办法
文章链接:http://soscw.com/index.php/essay/52426.html