我编写了自定义httpmodule,并且每个请求都会调用它。我想将值存储在我的第一个请求中,需要为后续请求检索此值。这在HttpModule中是否可行?
我知道HttpContext.Current.Items仅为单个请求保留值,我们不能根据我们的要求在项目中使用Session。
我们除了session \ HttpContext.Current.Items之外还有其他选项用于在HttpModule中存储值吗?
答案 0 :(得分:0)
只需添加一个静态属性。
例如:
public class TestModule : IHttpModule
{
private static string _myVal = null;
public void Init(HttpApplication httpApplication)
{
httpApplication.BeginRequest += new EventHandler(this.OnBeginRequest);
if (string.IsNullOrEmpty(_myVal)) {
_myval = "whatever";
}
//that this is set... you can use it.
}
//...
}