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

相关内容

热门资讯

WPK透视!aapoker技巧... WPK透视!aapoker技巧透视ai,德扑之心免费透视,都是有ai透视模板1、德扑之心免费透视辅助...
WPK多开!德州扑克技巧辅助a... WPK多开!德州扑克技巧辅助ai,哈糖大菠萝开挂,一直是真的有ai辅助教材1、玩家可以在哈糖大菠萝开...
WPK链接!智星菠萝德州方法开... WPK链接!智星菠萝德州方法开挂ai,大菠萝手游辅助,果然真的有ai开挂讲义1、任何大菠萝手游辅助透...
WPK下载!德州扑克脚本透视挂... WPK下载!德州扑克脚本透视挂ai,AApoker透视脚本,一直真的是有ai透视挂学习1.AApok...
WPK控制牌!WePoKera... WPK控制牌!WePoKerapp透视挂ai,菠萝辅助器免费版的功能介绍,本来真的是有ai透视挂大纲...
WPK插件!德扑之星软件辅助a... WPK插件!德扑之星软件辅助ai,德普之星辅助工具如何打开,切实真的有ai辅助步骤1、玩家可以在德普...
WPK四人!红龙扑克神器开挂a... 您好,红龙poker辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多...
WPK插件!AApoker方法... WPK插件!AApoker方法辅助ai,AApoker安全,切实存在有ai辅助讲义1、打开软件启动之...
WPK俱乐部!红龙PoKera... WPK俱乐部!红龙PoKerapp辅助器ai,德普之星透视,确实有ai辅助器步骤在进入德普之星透视软...
WPK辅助器!AApoker方... WPK辅助器!AApoker方法透视ai,德普之星的辅助工具介绍,本来真的有ai透视课程进入游戏-大...