Aspnet Core Identity 登录和注册在 Google Chrome 上不起作用。
创始人
2024-09-20 05:30:16
0

要解决Aspnet Core Identity登录和注册在Google Chrome上不起作用的问题,你可以尝试以下解决方法:

  1. 清除浏览器缓存:在Google Chrome浏览器中,按下Ctrl + Shift + Delete键,选择要清除的时间范围并选择清除缓存。

  2. 确保Cookie是启用的:在Chrome浏览器中,点击右上角的菜单按钮,选择“设置”,然后在“隐私和安全性”部分中,确保“允许所有网站保存和读取Cookie数据”选项是启用的。

  3. 检查代码逻辑:确保你的登录和注册代码没有任何错误。特别是在处理用户身份验证和授权的代码部分。

下面是一个简单的Aspnet Core Identity登录和注册的示例代码:

  1. 登录代码示例:
[HttpPost]
[AllowAnonymous]
public async Task Login(LoginViewModel model, string returnUrl = null)
{
    ViewData["ReturnUrl"] = returnUrl;

    if (ModelState.IsValid)
    {
        var user = await _userManager.FindByEmailAsync(model.Email);

        if (user != null && await _userManager.CheckPasswordAsync(user, model.Password))
        {
            await _signInManager.SignInAsync(user, model.RememberMe);
            return RedirectToAction(nameof(HomeController.Index), "Home");
        }

        ModelState.AddModelError(string.Empty, "Invalid login attempt.");
    }

    return View(model);
}
  1. 注册代码示例:
[HttpPost]
[AllowAnonymous]
public async Task Register(RegisterViewModel model, string returnUrl = null)
{
    ViewData["ReturnUrl"] = returnUrl;

    if (ModelState.IsValid)
    {
        var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
        var result = await _userManager.CreateAsync(user, model.Password);

        if (result.Succeeded)
        {
            await _signInManager.SignInAsync(user, isPersistent: false);
            return RedirectToAction(nameof(HomeController.Index), "Home");
        }

        AddErrors(result);
    }

    return View(model);
}

请注意,这只是一个基本示例,你可能需要根据你的实际要求进行适当的调整和修改。

相关内容

热门资讯

据相关数据显示!wepoker... 据相关数据显示!wepoker私局辅助,德扑之星辅助器app,总是真的是有挂(有挂透明挂)运德扑之星...
重大通报!德普之星辅助工具如何... 重大通报!德普之星辅助工具如何打开,wepoker私人局辅助挂,总是真的有挂(确实有挂)1、免费脚本...
反观!wepoker怎么设置盖... 反观!wepoker怎么设置盖牌,德普之星辅助工具如何设置,真是是真的有挂(有挂教程)1、操作简单,...
一分钟揭秘!aapoker能控... 一分钟揭秘!aapoker能控制牌吗,wepoker俱乐部辅助,竟然真的是有挂(真的有挂)1、让任何...
2026版辅助挂!sohoo开... 2026版辅助挂!sohoo开挂辅助,德普之星辅助软件,一直是有挂(确实有挂)1)德普之星辅助软件辅...
技巧知识分享!pokemomo... 技巧知识分享!pokemomo辅助工具,aapoker透视脚本入口,原来是真的有挂(有挂头条)1、操...
2026版方法!we poke... 2026版方法!we poker辅助器v3.3,德扑之星有透视辅助吗,其实是有挂(有挂秘笈)1、任何...
为了进一步!wepokerpl... 为了进一步!wepokerplus透视脚本免费,德普之星透视辅助软件是真的吗,本来真的是有挂(存在有...
必备教程!epoker透视底牌... 必备教程!epoker透视底牌,wepoker辅助器有哪些功能,果然存在有挂(确实有挂)必备教程!e...
第三方技巧!wepoker透视... 第三方技巧!wepoker透视脚本免费下载,德普辅助软件,切实真的有挂(有挂教学)1、进入到德普辅助...