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

相关内容

热门资讯

透视app!潮友会鱼虾蟹怎么发... 透视app!潮友会鱼虾蟹怎么发现软件控制,we-poker软件(辅助挂)详细开挂辅助安装您好:潮友会...
透视能赢!wepoker专用辅... 大家好,今天小编来为大家解答hhpoker软件靠谱吗这个问题咨询软件客服可以免费测试直接加微信(13...
透明插件!福建兄弟13水软件安... 透明插件!福建兄弟13水软件安装,来玩德州破解器(辅助挂)详细开挂辅助平台;无需打开直接搜索打开薇:...
透视美元局!微信小程序开心泉州... 透视美元局!微信小程序开心泉州辅助器,wepoker可以免费玩吗(辅助挂)详细开挂辅助脚本 了解更多...
透明教学!三哥玩摆头挂,wep... 三哥玩摆头挂开挂教程视频分享装挂详细步骤在当今的网络游戏中,三哥玩摆头挂作为一种经典的娱乐方式,吸引...
透视黑科技!越乡游嵊州辅助,e... 透视黑科技!越乡游嵊州辅助,epoker底牌透视(辅助挂)详细开挂辅助脚本;无需打开直接搜索微信(1...
透视系统!逗娱碰胡开挂,aap... 透视系统!逗娱碰胡开挂,aapoker如何设置胜率(辅助挂)详细开挂辅助安装这是一款可以让一直输的玩...
透视透明挂!衢州都莱罗松辅助软... 透视透明挂!衢州都莱罗松辅助软件,wepoker私人局俱乐部(辅助挂)详细开挂辅助平台这是一款可以让...
透视智能ai!wpk俱乐部有没... wpk俱乐部有没有辅助是一款专注玩家量身打造的游戏记牌类型软件,在wpk俱乐部有没有辅助这款游戏中我...
透视脚本!德扑圈透视挂,pok... 透视脚本!德扑圈透视挂,pokemmo脚本辅助器下载(辅助挂)详细开挂辅助插件;无需打开直接搜索薇:...