У меня есть приложение mvc4 WebAPI с перехватом замка Виндзор.
Класс перехватчика HttpContext.Current.Session
.
Когда я вызываю его непосредственно из перехватчика, он равен нулю.
Итак, я прочитал здесь, что мне нужно ввести сеанс, а не просто получить доступ к нему в перехватчике.HttpContext.Current.Session имеет значение null при введении его в перехватчик/или использование внутри внутреннего перехватчика (mvc4 webapi)
Это код, который я закончил с ...
protected void Application_Start()
{
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container.Kernel));
this.RegisterDependencyResolver();
this.container.Install(new WindsorWebApiInstaller());
}
public class WindsorWebApiInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
// the following interceptor needs Session object
container.Register(Component.For<IInterceptor>()
.ImplementedBy<SecurityInterceptor>()
.LifestylePerWebRequest()
.Named("SecurityInterceptor"));
// session is null here, So Castle wont inject it and throw exception...
container.Register(
Component.For<HttpSessionStateBase>().UsingFactoryMethod(
() => new HttpSessionStateWrapper(HttpContext.Current.Session)).LifestylePerWebRequest());
}
}
Есть ли другой способ получить доступ к сеансу с перехватчика?
Благодаря