【发布时间】:2017-09-20 14:38:11
【问题描述】:
我正在将一个较旧的小型 mvc5 应用程序移植到 .Net Core 2.0 和 MVC 6,更多的是作为学习如何做的练习。
在那个应用程序中,我有一个 Base Controller 类,它的主要工作是确保布局模型中包含用户的配置文件对象。
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (User.Identity.IsAuthenticated && Session["LayoutViewModel"] == null)
{
var lvm = new LayoutViewModel { AppUserId = User.Identity.GetUserId() };
lvm.LoggedInUserProfile =
Services.UserService.UserHelpers.GetCompleteProfileForLoggedInUser(lvm.AppUserId);
if (lvm.LoggedInUserProfile != null)
{
Session["LayoutViewModel"] = lvm;
}
else
{
Session["LayoutViewModel"] = null;
}
}
base.OnActionExecuted(filterContext);
}
我知道在 UserManager 中获取 UserId 的新方法,但我无法弄清楚如何设置 Session 变量,如果这在 .Net Core 2.0 中是可行的
【问题讨论】:
-
使用 Microsoft.AspNetCore.Session docs.microsoft.com/en-us/aspnet/core/fundamentals/…
标签: c# .net model-view-controller