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

相关内容

热门资讯

透视安装"佛手大菠萝... 透视安装"佛手大菠萝13道挂哪里"详细辅助玩家教你(可以买辅助神器);玩家必备必赢加哟《136704...
透视科技"大菠萝78... 透视科技"大菠萝789辅助器下载"详细辅助总结教程(可以挂飞机透明)科技教程也叫必备教程,这是一款功...
透视计算"xpoke... 1、透视计算"xpoker辅助器"详细辅助技巧教程(好友局透视软件)。2、xpoker辅助器透视辅助...
透视脚本"wepok... 您好,wepoker免费透视脚本这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】...
透视教学"wepok... 1、透视教学"wepoker私人局辅助挂"详细辅助黑科技教程(有机器人透明)。2、wepoker私人...
透视透视"wepok... 透视透视"wepoker脚本"详细辅助透明教程(购买模拟器技巧)1、点击下载安装,微扑克wpk插件透...
透视软件"hhpok... 透视软件"hhpoker德州透视挂"详细辅助可靠教程(轻量版透视系统方法)1、点击下载安装,微扑克w...
透视插件"哈糖大菠萝... 1、透视插件"哈糖大菠萝万能挂"详细辅助玩家教你(有辅助器攻略)(UU poker、哈糖大菠萝万能挂...
透视有挂"aapok... 透视有挂"aapoker发牌逻辑"详细辅助黑科技教程(有用辅助);《WPK辅助透视》‌:支持手机实时...
透视脚本"wepok... 透视脚本"wepoker游戏的安装教程"详细辅助实用技巧(作弊辅助技巧);建议优先通过wepoker...