我使用声明进行身份验证,并基于此文档auth user可以使用OwinContext登录。但是,与SecurityManager.Authenticate不同,OwinContext不会返回登录失败的原因。
var owinContext = SystemManager.CurrentHttpContext.Request.GetOwinContext();
var challengeProperties = ChallengeProperties.ForLocalUser(username, password, provider, isPersistent, errorRedirectUrl);
challengeProperties.RedirectUri = successRedirectUrl;
// this call will trigger redirects to the appropriate Identity Provider
owinContext.Authentication.Challenge(challengeProperties, ClaimsManager.CurrentAuthenticationModule.STSAuthenticationType);
我需要知道登录失败的原因。例如SecurityManager.Authenticate中的UserLoggingReason之类的内容,以便我可以相应地处理结果。
User user;
UserLoggingReason result = SecurityManager.AuthenticateUser(
provider,
username,
password,
isPersistent,
out user);
if (result != UserLoggingReason.Success)
{
SystemManager.CurrentHttpContext.Response.Redirect(errorRedirectUrl, false);
}
else
{
SystemManager.CurrentHttpContext.Response.Redirect(successRedirectUrl, false);
}
最佳答案
我建议您看一下Sitefinity小部件的方式,例如LoginForm这样做:
https://github.com/Sitefinity/feather-widgets/blob/master/Telerik.Sitefinity.Frontend.Identity/Mvc/Models/LoginForm/LoginFormModel.cs#L285
您可能会对GetReturnUrl实现感兴趣:
https://github.com/Sitefinity/feather-widgets/blob/master/Telerik.Sitefinity.Frontend.Identity/Mvc/Models/LoginForm/LoginFormModel.cs#L486