2016-03-10 29 views
0

我使用Azure会话状态提供程序(DistributedCacheSessionStateStoreProvider),它的工作原理非常好。但现在我有一个定制的HttpModule,它结合了脚本。我在中登录PostAcquireRequestState。我然后通过一个构造发送Session参考我的自定义过滤器:在Response.Filter中或之后的HttpModule中访问会话?

application.Response.Filter = new CombinationFilter(application.Response.Filter, application, application.Session) 

修改我在过滤器Session和它完美的作品在本地主机(标准会议提供商)。但发布在Azure当我修改Session的值在那里,但后来他们消失(他们没有坚持)。只有在过滤器中添加的那些消失,那些之前那些仍然存在。我怀疑最后的同步是在ReleaseRequestState(根据名称)。这显然是在我的Response.Filter处理之前。

  1. 如何访问Session链后,仍然保存呢?

  2. 或者我可以在ReleaseRequestState之前以某种方式使用过滤器吗?

回答

0

我终于解决了它。对于其他人可能想知道如何实现这一点:

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) 
    } 
};