403 - 禁止:访问被拒绝。登录 ASP.Net Core 2.2 后

问题描述 投票:0回答:1

我最近更改了我的托管服务器, 我登录后随机收到此错误消息:

403 - 禁止:访问被拒绝。

您无权使用您提供的凭据查看此目录或页面。

当我删除浏览器中的相关 cookie 时,网站会再次加载。

我使用 cookie 身份验证而不使用 ASP.NET Core Identity,如下所述: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-2.2

startup.cs代码:

  services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            }).AddCookie(options =>
            {
                
                options.LoginPath = "/Login";
                options.LogoutPath = "/Logout";
                options.ExpireTimeSpan = TimeSpan.FromMinutes(43200);
            });

并登录零件代码:

            User user = await _userService.LoginUserAsync(login.Email, login.Password);
            var claims = new List<Claim>()
            {
                new Claim(ClaimTypes.Name,user.UserName),
                new Claim(ClaimTypes.NameIdentifier,user.UserID.ToString())
            };
            var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
            var pricipal = new ClaimsPrincipal(identity);

            var properties = new AuthenticationProperties()
            {
                IsPersistent = login.RememberMe
            };

            await HttpContext.SignInAsync(pricipal, properties);

我之前的托管计划从未遇到过同样的问题。

此问题与主机设置有关吗?

authentication asp.net-core cookies
1个回答
0
投票

我也有这个问题。你解决问题了吗? 如果你解决了,能解释一下你是怎么做到的吗?

© www.soinside.com 2019 - 2024. All rights reserved.