[英]AspNet.Identity role Management
我正在使用帶有EF codefirst的Asp.net 4.5.1 webForm應用程序。 對於身份驗證,我使用的是Microsoft.AspNet.Identity。 我要在檢查用戶正確之后在登錄頁面中還要檢查用戶的角色。 如果用戶具有管理員角色,則將用戶發送到admin文件夾(頁面),或者如果用戶具有用戶角色,則將用戶發送到用戶文件夾(頁面)。 如何檢查用戶是否具有管理員角色?
這是我的登錄代碼:
protected void btnLogin_Click(object sender, EventArgs e)
{
if (IsValid)
{
// Validate the user password
var manager = new UserManager();
ApplicationUser user = manager.Find(inputEmail.Text, inputPassword.Text);
if (user != null)
{
IdentityHelper.SignIn(manager, user, false);
if (//user is in admin role)
{
Response.Redirect("UserPage");
}
else
{
Response.Redirect("AdminPage");
}
}
else
{
//Show error message that User is Incorrect
}
}
}
嘗試使用UserManager.IsInRole(User.Identity.GetUserId(), "RoleName")
另外參考: 用字符大小寫理解IsInRole
提示:嘗試在Visual Studio的“對象瀏覽器”(Ctrl + Alt + J)中瀏覽任何程序集。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.