我有使用ServiceStack的.NET MVC5应用程序。在AuthenticationFilter中,我想检查特定属性是否在会话中。
在AuthController中:
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
}
}
我的自定义会话从服务堆栈实现AuthUserSession。
提前致谢!
答案 0 :(得分:2)
您的Controller需要继承ServiceStackController
,然后您应该能够访问UserSession:
var ssController = filterContext.Controller as ServiceStackController;
if (ssController == null) return;
var session = ssController.ServiceStackProvider.SessionAs<CustomerUserSession>();