Asp.net 在响应中或之后访问HttpModule中的会话。是否筛选?
我正在使用Azure会话状态提供程序(Asp.net 在响应中或之后访问HttpModule中的会话。是否筛选?,asp.net,session,azure,iis,httpmodule,Asp.net,Session,Azure,Iis,Httpmodule,我正在使用Azure会话状态提供程序(DistributedCacheSessionStateStoreProvider),它工作得很好。但是现在我有了一个结合脚本的定制HttpModule。我正在挂接响应。在PostAcquireRequestState中筛选。然后,我通过构造函数将会话引用发送到我的自定义筛选器: application.Response.Filter = new CombinationFilter(application.Response.Filter, applicati
DistributedCacheSessionStateStoreProvider
),它工作得很好。但是现在我有了一个结合脚本的定制HttpModule
。我正在挂接响应。在PostAcquireRequestState
中筛选。然后,我通过构造函数将会话
引用发送到我的自定义筛选器:
application.Response.Filter = new CombinationFilter(application.Response.Filter, application, application.Session)
在我的过滤器中修改会话
,它可以在本地主机(标准会话提供程序)上完美工作。但是当我修改会话
时,这些值会在Azure上发布,但随后它们会消失(不会持久化)。只有那些添加到过滤器中的才会消失,那些以前存在的仍然存在。我怀疑最后一次同步在ReleaseRequestState
(基于名称)内。这显然是在处理我的响应。过滤器之前
我如何访问链中稍后的会话
,并且仍然存储它?
或者我可以在发布请求状态之前使用过滤器吗
我终于解决了。对于其他可能想知道如何实现这一点的人:
application.PostRequestHandlerExecute += (sender, args) =>
{
if (YourCondition)
{
// performs premature flush to force the filter
application.Response.Flush();
String content = ((CombinationFilter) application.Response.Filter).OriginalContent;
// we need to remove the filter to not execute twice
application.Response.Filter = null;
// do my stuff here, we still have a Session and also the original content
// the content is stored on a filter in Flush() method before modification
// (by me => my custom property)
// do not write any other content
application.Response.SuppressContent = true;
// onwards it still saves Session in ReleaseRequestState (presumably)
}
};