我使用Windor城堡经由工厂方法来包装的HttpContext成HttpContextWrapper。HttpContextBase:会话为null
container.Register(
Component.For<HttpContextBase>()
.LifeStyle.PerWebRequest
.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
我有一个叫SessionStorage
类访问HttpContext.Current.Session
。我注册这样说:
container.Register(
Component.For<ISessionStorage>()
.LifeStyle.PerWebRequest
.ImplementedBy<HttpSessionStorage>());
的HttpSessionStorage
类:
public class HttpSessionStorage : ISessionStorage
{
public HttpContextBase httpContext { get; set; }
public void Remove(string key)
{
httpContext.Session.Remove(key);
}
public T Get<T>(string key)
{
return (T)httpContext.Session[key];
}
public void Set<T>(string key, T value)
{
httpContext.Session[key] = value;
}
}
当我使用这种方式,那么在约40%的情况下的Session
属性null and only if 请求的价格非常高。
奇怪的是,如果我使用的HttpContext.Current
代替httpContext
,它适用于所有情况。
public class HttpSessionStorage : ISessionStorage
{
public HttpContextBase httpContext { get; set; }
public void Remove(string key)
{
HttpContext.Current.Session.Remove(key);
}
public T Get<T>(string key)
{
return (T)HttpContext.Current.Session[key];
}
public void Set<T>(string key, T value)
{
HttpContext.Current.Session[key] = value;
}
}
它是与温莎城堡,但我不能发现问题。我注册了我可以作为PerWebRequest
(NHibernate会话工厂除外)的所有内容。
有人有一个想法我可以检查什么?
了Lg
warappa
你能定义“非常高的请求率”吗?你能发布一个失败的测试吗?你是否试过让它暂时而不是PerWebRequest? – 2011-05-23 13:23:03
“非常高的请求率”:ImageController必须提供〜25张图片。每次向任何控制器发出请求(也是这样),主体将创建并存储在会话中(通过HttpSessionStorage)。就像上面说的那样,有时保存会失败,因为包装中会话中的会话为空。 – 2011-05-23 18:46:18