I have e .NET MVC5 Application with ServiceStack.在身份验证过滤器中,我想检查会话中是否有特定属性。
在身份验证控制器中:
var customerSession = SessionAs<CustomerUserSession>();
customerSession.property = "some value";
在筛选器中:
public class MyAuthFilter : ActionFilterAttribute, IAuthenticationFilter
{
public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
// I want to access that property here
}
}
我的自定义会话从服务堆栈实现身份验证用户会话。
提前感谢!
您的控制器需要继承ServiceStackController
然后您应该能够通过以下方式访问用户会话:
var ssController = filterContext.Controller as ServiceStackController;
if (ssController == null) return;
var session = ssController.ServiceStackProvider.SessionAs<CustomerUserSession>();