Asp.net core ASP.NET根据主机禁用授权

Asp.net core ASP.NET根据主机禁用授权,asp.net-core,Asp.net Core,我有一个ASP.NET核心应用程序,我用Authorize属性修饰了我的conroller/actions。在Startup.cs中,我定义了如下身份验证: services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme); 在IIS或IIS Express中运行应用程序时,授权有效。但是,我希望在不支持Windows身份验证的主机(如控制台应用程序)中

我有一个ASP.NET核心应用程序,我用Authorize属性修饰了我的conroller/actions。在Startup.cs中,我定义了如下身份验证:

services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);
在IIS或IIS Express中运行应用程序时,授权有效。但是,我希望在不支持Windows身份验证的主机(如控制台应用程序)中运行时禁用授权

我正在考虑这样做:

services.AddMvc(options =>
{
     if (!isWindowsAuthenticationSupported)
        options.Filters.Add(new AllowAnonymousFilter());
});

如果这是正确的方法,我将如何设置isWindowsAuthenticationSupported变量?

以下是确定是否支持Windows身份验证的代码:

string iisHttpAuth = Environment.GetEnvironmentVariable("ASPNETCORE_IIS_HTTPAUTH");
bool isWindowsAuthenticationSupported = false;
if (iisHttpAuth != null && iisHttpAuth.ToLowerInvariant().StartsWith("windows"))
    isWindowsAuthenticationSupported = true;