Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc ASP标识自定义密码登录不起作用_Asp.net Mvc_Asp.net Identity - Fatal编程技术网

Asp.net mvc ASP标识自定义密码登录不起作用

Asp.net mvc ASP标识自定义密码登录不起作用,asp.net-mvc,asp.net-identity,Asp.net Mvc,Asp.net Identity,我目前正在尝试在ApplicationSignInManager上实现我自己的自定义PasswordSignInAsync方法,但到目前为止,它无法进行身份验证,即使该方法不会引发任何错误,以下是我在IdentityConfig.cs中的代码。我已经将ASP标识配置为作为主键使用 我不知道我是否遗漏了创建正确用户登录的附加操作,有人能告诉我遗漏了什么,我还没有找到任何代码。此自定义函数将附加参数传递给ApplicationUser的GenerateUserIdentityAsync方法 publ

我目前正在尝试在ApplicationSignInManager上实现我自己的自定义PasswordSignInAsync方法,但到目前为止,它无法进行身份验证,即使该方法不会引发任何错误,以下是我在IdentityConfig.cs中的代码。我已经将ASP标识配置为作为主键使用

我不知道我是否遗漏了创建正确用户登录的附加操作,有人能告诉我遗漏了什么,我还没有找到任何代码。此自定义函数将附加参数传递给ApplicationUser的GenerateUserIdentityAsync方法

public class ApplicationSignInManager : SignInManager<ApplicationUser, long>
    {
        public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
            : base(userManager, authenticationManager)
        {
        }

        public async Task<SignInStatus> PasswordSystemSignInAsync(string userName, string password, bool IsPersistent, bool shouldLockout, bool IsAdministrative, string securityCode = null)
        {
            var user = await UserManager.FindByNameAsync(userName);
            if(user != null)
            {
                bool passwordCheck = await UserManager.CheckPasswordAsync(user, password);
                if (passwordCheck)
                {
                    var signInUser = await user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager, IsAdministrative);
                    if (signInUser.IsAuthenticated)
                    {
                        return SignInStatus.Success;
                    }
                    return SignInStatus.Failure;
                }
                return SignInStatus.Failure;
            }
            return SignInStatus.Failure;
        }
}
公共类应用程序SignInManager:SignInManager
{
公共应用程序签名管理器(ApplicationUserManager用户管理器、IAAuthenticationManager authenticationManager)
:base(userManager、authenticationManager)
{
}
公共异步任务PasswordSystemSignInAsync(字符串用户名、字符串密码、bool IsPersistent、bool shouldllockout、bool IsAdministrative、字符串securityCode=null)
{
var user=await UserManager.FindByNameAsync(用户名);
如果(用户!=null)
{
bool passwordCheck=wait UserManager.CheckPasswordAsync(用户,密码);
if(密码检查)
{
var signInUser=wait user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager,IsAdministrative);
如果(signInUser.IsAuthenticated)
{
返回信号状态成功;
}
返回信号状态失败;
}
返回信号状态失败;
}
返回信号状态失败;
}
}

在方法中,您创建了标识,但未登录生成的标识。考虑这一点:

public async Task<SignInStatus> PasswordSystemSignInAsync(string userName,string password, bool IsPersistent, bool shouldLockout, bool IsAdministrative, string securityCode = null)
{
    var user = await UserManager.FindByNameAsync(userName);
    if(user != null)
    {
        bool passwordCheck = await UserManager.CheckPasswordAsync(user, password);
        if (passwordCheck)
        {
            var userIdentity = await user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager, IsAdministrative);
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
            AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = IsPersistent}, userIdentity);
            return SignInStatus.Success;
        }
        return SignInStatus.Failure;
    }
    return SignInStatus.Failure;
}
public async Task PasswordSystemSignInAsync(字符串用户名、字符串密码、bool IsPersistent、bool shouldllockout、bool IsAdministrative、字符串securityCode=null)
{
var user=await UserManager.FindByNameAsync(用户名);
如果(用户!=null)
{
bool passwordCheck=wait UserManager.CheckPasswordAsync(用户,密码);
if(密码检查)
{
var userIdentity=wait user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager,IsAdministrative);
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie、DefaultAuthenticationTypes.TwoFactorCookie);
SignIn(新的AuthenticationProperties{IsPersistent=IsPersistent},userIdentity);
返回信号状态成功;
}
返回信号状态失败;
}
返回信号状态失败;
}

AuthenticationManager.signout的具体功能是什么?在登录时,我必须设置所有属性吗?该方法是否从Startup.Auth?@Forcefield检索所有其他属性,以确保用户尚未登录,只需调用
signOut
方法即可注销用户。该方法是安全的,如果用户尚未登录,则不会执行任何操作。不,您不必设置所有属性,只需在您想要更改时填充即可。这就是方法!仅从参数传递ispersist是我对您的答案所做的唯一更改。Identity SignIn manager是否在某处引用了此信息?我找不到任何自定义PasswordSigning方法的示例,该方法没有调用base oneIdentity是一个开源项目,您可以查看