Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 在ASP.NET核心中处理Windows和匿名身份验证_Authentication_Asp.net Core_Windows Authentication - Fatal编程技术网

Authentication 在ASP.NET核心中处理Windows和匿名身份验证

Authentication 在ASP.NET核心中处理Windows和匿名身份验证,authentication,asp.net-core,windows-authentication,Authentication,Asp.net Core,Windows Authentication,我有一个ASP.NETCore2.0的项目。如果可能的话,我希望用户通过Windows身份验证自动登录,如果没有,则返回到登录屏幕。如果我只启用Windows身份验证而不启用匿名身份验证,那么Windows身份验证会很好地命中我的中间件,一切都很好。但是,如果同时启用了Windows和anonymous,则我的中间件将获得一个空的ClaimsIdentity,而不是WindowsIdentity,即使它们是通过Windows登录的 从另一个答案中,我发现使用以下代码强制进行Windows身份验证

我有一个ASP.NETCore2.0的项目。如果可能的话,我希望用户通过Windows身份验证自动登录,如果没有,则返回到登录屏幕。如果我只启用Windows身份验证而不启用匿名身份验证,那么Windows身份验证会很好地命中我的中间件,一切都很好。但是,如果同时启用了Windows和anonymous,则我的中间件将获得一个空的
ClaimsIdentity
,而不是
WindowsIdentity
,即使它们是通过Windows登录的

从另一个答案中,我发现使用以下代码强制进行Windows身份验证检查:

await HttpContext.ChallengeAsync(IISDefaults.AuthenticationScheme);
有了这个,我可以使用cookies来强制挑战,如果还没有尝试过的话,也可以显示我的登录页面。现在的问题是,如果用户没有登录,浏览器会在Windows挑战上抛出一条内置的登录消息


有没有可能比我现在所做的更好地实现这个目标?用户必须从强制弹出窗口中单击“取消”才能进入我的登录屏幕,这很烦人,但如果没有更好的方法,那就只能这样了。

你解决过这个问题吗?我也想做同样的事情。请让我知道