0
我有一個使用實體框架的現有數據庫。註冊和登錄工作,但我想爲Signin狀態添加一個附加狀態:未經授權。MVC(ASP.NET身份)使用實體框架自定義登錄狀態
下面是在登錄的代碼:我添加的代碼段以上部分向你展示我想要什麼
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
'case SignInStatus.UnAuthorized:
return View("UnAuthorized");' //I want to add this
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
。我找到了上面使用的狀態。在下面的代碼片段中提供,但我無法修改此文件:
namespace Microsoft.AspNet.Identity.Owin
{
//
// Summary:
// Possible results from a sign in attempt
public enum SignInStatus
{
//
// Summary:
// Sign in was successful
Success = 0,
//
// Summary:
// User is locked out
LockedOut = 1,
//
// Summary:
// Sign in requires addition verification (i.e. two factor)
RequiresVerification = 2,
//
// Summary:
// Sign in failed
Failure = 3
}
}
我可能會補充說我是MVC的新手。
任何人都可以指出我正確的方向能夠添加自定義登錄狀態? PS:授權字段確實存在於我的數據庫中,如果用戶已授權或不登錄,這是我想要提取的地方。
感謝您的幫助。