我已经编写了自定义的httpmodule,它会在每次请求时被调用。我希望在第一次请求时存储该值,并且需要为后续请求检索该值。这在HttpModule中是可能的吗?
我知道HttpContext.Current.Items只为单个请求保留值,我们不能根据我们的要求在我们的项目中使用会话。
除了在HttpModule中存储值的session\HttpContext.Current.Items之外,我们还有其他选择吗?
发布于 2015-03-13 02:24:41
只需添加一个静态属性。
例如:
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.
}
//...}
https://stackoverflow.com/questions/29000922
复制相似问题