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

相关内容

热门资讯

透视肯定!werplan外挂(... 透视肯定!werplan外挂(透视)确实存在有挂(详细辅助切实教程);1、ai辅助优化,发牌逻辑科技...
透视总结!wpk免费辅助(透视... 透视总结!wpk免费辅助(透视)一直有挂(详细辅助AI教程)1、玩家可以在软件透明挂俱乐部对游戏的模...
透视插件!pokermaste... 透视插件!pokermaster修改器(透视)原来真的是有挂(详细辅助透牌教程)1、透视辅助简单,软...
透视神器!wepoker轻量版... 透视神器!wepoker轻量版透视(透视)其实是有挂(详细辅助透牌教程)1、玩家可以在软件透明挂俱乐...
透视黑科技!wepokerh5... 透视黑科技!wepokerh5破解(透视)切实是真的有挂(详细辅助爆料教程)1、系统规律教程、辅助透...
透视app!wepoker免费... 透视app!wepoker免费钻石(透视)果然真的有挂(详细辅助插件教程);1)辅助挂:进一步探索辅...
透视游戏!aapoker辅助软... 透视游戏!aapoker辅助软件合法吗(透视)原来存在有挂(详细辅助解密教程)小薇(透视辅助)致您一...
透视app!wejoker辅助... 透视app!wejoker辅助脚本(透视)切实存在有挂(详细辅助安装教程);1、透视app!wejo...
透视私人局!hhpoker可以... 透视私人局!hhpoker可以开挂吗(透视)切实真的是有挂(详细辅助透明挂教程);暗藏猫腻,小编详细...
透视黑科技!wepoker亲友... 透视黑科技!wepoker亲友圈有用吗(透视)好像真的有挂(详细辅助细节揭秘);1、打开软件启动之后...