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

相关内容

热门资讯

德州ai辅助!德州nzt实战(... 1、德州ai辅助!德州nzt实战(透视)真是有挂(详细辅助细节方法);代表性(透视辅助软件透明挂)高...
透视最新!德朴之星脚本,hhp... 透视最新!德朴之星脚本,hhpoker软件靠谱吗(详细辅助可靠教程);1、德朴之星脚本机器人多个强度...
wpk透视辅助测试!wpeok... wpk透视辅助测试!wpeoke软件下载(透视)果然有挂(详细辅助详细教程)1、wpk透视辅助测试a...
透视ai!wpk辅助插件,we... 透视ai!wpk辅助插件,wepokerplus脚本(详细辅助教你教程)1、首先打开wpk辅助插件最...
透视教学!wpk透视辅助软件,... 透视教学!wpk透视辅助软件,hhpoker透视工具(详细辅助解说技巧)1)wpk透视辅助软件辅助挂...
wepoke一定有挂!智星德州... wepoke一定有挂!智星德州菠萝偷偷看功能(透视)确实真的是有挂(详细辅助普及教程)是一款可以让一...
透视辅助!wpk透视脚本视频,... 透视辅助!wpk透视脚本视频,智星菠萝透视(详细辅助微扑克教程)1、完成wpk透视脚本视频透视辅助安...
wepoke计算辅助!wepo... wepoke计算辅助!wepoke智能ai(透视)本来真的有挂(详细辅助靠谱教程)1、金币登录送、破...
透视了解!wepoker辅助器... 透视了解!wepoker辅助器下载,wpk俱乐部是做什么的(详细辅助新2025版);1、wepoke...
wepok软件透明挂!wpk的... wepok软件透明挂!wpk的发牌机制(透视)本来真的是有挂(详细辅助安装教程);wepok软件透明...