我正在尝试创建一个操作过滤器,该过滤器会将登录的注册用户重定向到一个页面,该页面要求他们在允许其访问网站上的任何其他页面之前完成其个人资料。我可以从user id
代码块中获取Action Filter
,但是有没有办法使用id
从Identity User
表中获取用户详细信息?我已经扩展了默认身份表以包括列Status
,并且我想对该列进行检查。这是我到目前为止的内容:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Prevent redirect for unauthenticated users
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
{
return;
}
// Prevent redirect if user is already on complete registration page
if (filterContext.ActionDescriptor.ControllerDescriptor.ControllerName == "Account" &&
filterContext.ActionDescriptor.ActionName == "CompleteRegistration")
{
return;
}
var userId = filterContext.HttpContext.User.Identity.GetUserId();
var user = // How can I get user details here?
if (user.Status.Equals(AccountStatus.Registered))
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary
{
{ "controller", "Account" },
{ "action", "CompleteRegistration" }
});
}
}