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

相关内容

热门资讯

查到实测!we-poker辅助... 查到实测!we-poker辅助,hhpoker是真的还是假的,扑克教程(有挂攻略)是一款可以让一直输...
一分钟揭秘!wepoker怎么... 一分钟揭秘!wepoker怎么增加运气,pokemmo脚本辅助下载,攻略教程(有挂辅助);最新版20...
每日必看教程!智星菠萝辅助,h... 每日必看教程!智星菠萝辅助,hhpoker透视脚本下载,必赢教程(有挂技巧);科技安装教程;1367...
推荐十款!pokemmo手机辅... 推荐十款!pokemmo手机辅助软件,hhpoker有没有外挂,大神讲解(有挂攻略)是一款可以让一直...
终于懂了!红龙poker辅助平... 终于懂了!红龙poker辅助平台,pokemmo脚本,详细教程(有挂技巧);致您一封信;亲爱红龙po...
让我来分享经验!wepoker... 1、让我来分享经验!wepoker私人局辅助,wepoker怎么设置透视,新2025版(有挂技巧)。...
每日必看推荐!wepoker有... 每日必看推荐!wepoker有没有辅助,cloudpoker怎么开挂,新版2025教程(有挂方法)关...
分享实测!wepoker提高好... 分享实测!wepoker提高好牌率,wepoker有没有辅助,必备教程(有挂攻略);实战中需综合运用...
避坑细节!hhpoker破解工... 自定义wepoker插件功能辅助器系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用...
今日头条!德州透视是真的吗,w... 今日头条!德州透视是真的吗,wejoker辅助机器人,科技教程(有挂透明)是一款可以让一直输的玩家,...