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身份验证的问题了。

相关内容

热门资讯

一秒答解!wepoker怎么挂... 《一秒答解!wepoker怎么挂飞机,竞技联盟透视,透明挂教程(有挂攻略)》 wepoker怎么挂飞...
2024教程!德普之星透视辅助... 2024教程!德普之星透视辅助软件是真的吗,hhpoker有作弊的吗,2025教程(有挂技巧);小薇...
实操分享!wepokerh5破... 您好,德州私人局怎么透视这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家...
总算了解!菠萝辅助器免费版的功... 总算了解!菠萝辅助器免费版的功能介绍,wepoker有辅助工具吗,详细教程(有挂教程);支持2-10...
玩家必看秘籍!wepoker安... 玩家必看秘籍!wepoker安装教程,we poker辅助器,透明挂教程(有挂教程);原来确实真的有...
今日公布!红龙poker作弊指... 今日公布!红龙poker作弊指令,wepoker怎么提高运气,安装教程(有挂教程);wepoker怎...
揭秘一下!hhpoker万能辅... 揭秘一下!hhpoker万能辅助器,wejoker黑侠辅助器,软件教程(有挂方法),支持语音通讯、好...
实测发现!德普之星透视辅助,w... 实测发现!德普之星透视辅助,wepoker私局代打,wpk教程(有挂透明);致您一封信;亲爱德普之星...
安装程序教程!htx矩阵wep... 安装程序教程!htx矩阵wepoker辅助,cloudpoker作弊,安装教程(有挂攻略);玩家必备...
重大通报!智星德州辅助译码插件... 1、重大通报!智星德州辅助译码插件靠谱吗,约局吧德州透视,玩家教你(有挂神器);详细教程。2、智星德...