【发布时间】:2014-04-02 13:24:02
【问题描述】:
我正在研究 Asp.Net MVC 和服务堆栈。我正在尝试实现这一点,在服务堆栈服务类中使用 asp.net mvc 会话。也就是说,
Public ActionResult Index()
{
Session["username"]="xxx";
return View();
}
从现在开始,我需要能够在服务堆栈服务类中使用Session["username"],但我无法在服务堆栈服务类中使用会话。 HttpContext.Current.Session 抛出空异常。我已经提到了 Social Bootstrap Api 服务堆栈示例项目,因为他们使用CustomUserSession 类,这意味着在身份验证后他们会将数据存储到会话中,例如,
Plugins.Add(new AuthFeature(
() => new CustomUserSession(), //Use your own typed Custom UserSession type
new IAuthProvider[] {
new CredentialsAuthProvider()
}));
但在我的应用程序中没有身份验证机制,但我需要将一些信息存储到会话中并在服务堆栈服务类中使用该会话。
要在服务堆栈中启用会话而无需我们使用的身份验证,
Plugins.Add(new SessionFeature());
那么如何在没有身份验证的情况下在服务堆栈中使用 asp.net mvc 会话。请指导我。
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4 session servicestack