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

相关内容

热门资讯

透视总结!aapoker辅助器... 透视总结!aapoker辅助器是真的吗(透视)最初存在有挂(详细辅助曝光教程);《WPK辅助透视》‌...
透视模拟器(wepoKe)微扑... 透视模拟器(wepoKe)微扑克数据辅助软件(透视)详细辅助透视教程,支持语音通讯、好友开房及战队组...
透视辅助!hhpoker透视脚... 透视辅助!hhpoker透视脚本(透视)详细辅助细节方法(确实是有挂)1、很好的工具软件,可以解锁游...
透视美元局!哈糖大菠萝万能挂(... 此外,数据分析德州(哈糖大菠萝万能挂)辅助神器app还具备辅助透视行为开挂功能,通过对客户哈糖大菠萝...
透视透视(WepokE)智星德... 1、透视透视(WepokE)智星德州菠萝外挂检测(透视)详细辅助AI教程(UU poker、智星德州...
透视挂!wepoker透视脚本... 透视挂!wepoker透视脚本网页(透视)详细辅助技巧教程(真是是真的有挂)一、wepoker透视脚...
透视脚本!hhpoker透视脚... 自定义hhpoker透视脚本下载系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅...
透视玄学(wepOkE)wep... 透视玄学(wepOkE)wepoke存在外挂么(透视)详细辅助可靠教程是由北京得wepoke存在外挂...
透视神器!aapoker透视脚... 透视神器!aapoker透视脚本安装包(透视)详细辅助大神讲解(原来存在有挂)1、进入到aapoke...
透视智能ai!wepoker辅... 1、透视智能ai!wepoker辅助透视软件(透视)总是是有挂(详细辅助攻略教程)。2、wepoke...