ASPNET5.0webapp在移动端登录遇到的问题(Windows身份验证)。
创始人
2024-09-20 06:30:25
0

该问题可能是由于移动设备上默认不支持Windows身份验证而引起的。解决该问题的一种方法是使用cookie身份验证代替Windows身份验证。

首先,需要在Startup.cs文件的ConfigureServices方法中添加以下行,以启用cookie身份验证:

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => { options.LoginPath = new PathString("/Account/Login/"); options.AccessDeniedPath = new PathString("/Account/Forbidden/"); });

然后,在AccountController的Login方法中,添加以下代码来设置用户的cookie凭据:

var claims = new List() { new Claim(ClaimTypes.NameIdentifier, "userId"), new Claim(ClaimTypes.Name, "userName"), new Claim(ClaimTypes.Email, "userEmail") };

var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));

最后,在需要验证身份的控制器或操作中,添加以下代码以确保用户已经通过cookie身份验证:

[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)] public IActionResult MySecuredAction() { // Do something that requires authenticated user }

这样,在移动设备上使用ASPNET 5.0 web app时,应该就不会遇到Windows身份验证的问题了。

相关内容

热门资讯

黑科技辅助!wepoke智能a... 黑科技辅助!wepoke智能ai,(红龙扑克下载)一直存在有挂,爆料教程(发现有挂);亲,有的,ai...
黑科技辅助!wepoke智能a... 黑科技辅助!wepoke智能ai辅助工具,(扑克之城)好像是真的有挂,攻略教程(有挂方法)是一款可以...
黑科技辅助!wepoke辅助插... 黑科技辅助!wepoke辅助插件安装,(菠萝德州软件)原先是真的有挂,黑科技教程(详细教程);菠萝德...
黑科技辅助!wepoke智能a... 黑科技辅助!wepoke智能ai辅助工具,(德州ai盈利)一直是有挂,AI教程(有挂讲解);德州ai...
黑科技辅助!wepoke透明黑... 黑科技辅助!wepoke透明黑科技,(AAPoKer模拟器)往昔是有挂,科技教程(真的有挂);AAP...
黑科技辅助!wepoke辅助插... 黑科技辅助!wepoke辅助插件安装,(微扑克机器人)总是存在有挂,揭秘教程(果真有挂);微扑克机器...
黑科技辅助!wepoke智能a... 黑科技辅助!wepoke智能ai辅助工具,(德扑之星代打)都是真的有挂,必胜教程(今日头条),德扑之...
黑科技辅助!wepoke智能a... 黑科技辅助!wepoke智能ai辅助工具,(AAPoKerai机器人)真是是有挂,力荐教程(有挂辅助...
黑科技辅助!wepoke有挂真... 黑科技辅助!wepoke有挂真的有挂,(红龙扑克机制)原来有挂,高科技教程(有挂教程);亲,有的,a...
黑科技辅助!wepoke辅助插... 黑科技辅助!wepoke辅助插件,(WePoKe黑科技)先前真的是有挂,2025新版教程(发现有挂)...