在 ChangePassword 页面上重定向用户并 "block" 他
Redirect a user and "block" him on the ChangePassword page
是一个 asp.net MVC 应用程序。
我正在使用 Asp.NetCore.Identity
我想在登录后如果 "password has never been changed"(我知道如何调节)将他重定向到 ChangePassword 页面并阻止任何其他页面,直到更改密码。(或者当他想访问其他页面时重定向在更改密码时)
有什么想法吗?
也许要覆盖授权属性?
我通过创建自定义授权 class 做了同样的事情。为此,我们必须创建一个新的 class 并在其上继承 AuthorizeAttribute class ,然后重写一个名为 AuthorizeCore 的方法,因为它是自定义授权检查的入口点。
public class CheckAuthorization: AuthorizeAttribute
{
public CheckAuthorization(){
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
bool _isAuthorize = false;
if(password change required)
httpContext.Response.Redirect("~/home/changepassword");
if (!httpContext.User.Identity.IsAuthenticated)
return false;
// Check roles
return true;
}
}
然后像这样使用您的授权属性
[CheckAuthorization(Roles = "admin, superadmin, root")]
public ActionResult DashBoard()
{
return View();
}
是一个 asp.net MVC 应用程序。 我正在使用 Asp.NetCore.Identity
我想在登录后如果 "password has never been changed"(我知道如何调节)将他重定向到 ChangePassword 页面并阻止任何其他页面,直到更改密码。(或者当他想访问其他页面时重定向在更改密码时)
有什么想法吗? 也许要覆盖授权属性?
我通过创建自定义授权 class 做了同样的事情。为此,我们必须创建一个新的 class 并在其上继承 AuthorizeAttribute class ,然后重写一个名为 AuthorizeCore 的方法,因为它是自定义授权检查的入口点。
public class CheckAuthorization: AuthorizeAttribute
{
public CheckAuthorization(){
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
bool _isAuthorize = false;
if(password change required)
httpContext.Response.Redirect("~/home/changepassword");
if (!httpContext.User.Identity.IsAuthenticated)
return false;
// Check roles
return true;
}
}
然后像这样使用您的授权属性
[CheckAuthorization(Roles = "admin, superadmin, root")]
public ActionResult DashBoard()
{
return View();
}