简体   繁体   中英

How to enable SSL, Windows Authentication and Anonymous Authentication through Console

From the project properties we could do it as follows for IIS Express 在此处输入图片说明

but I am using the console for a IdentityServer4 Identity provider host. 在此处输入图片说明 so I must configure it from Program.cs or Startup.cs since I have no such options on project properties when using console. 在此处输入图片说明

IIS and Windows authentication is not applicable when you host your service with the console app. I am using the below code enable HTTPS for my identity server

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseKestrel(options => 
                {
                    options.Listen(IPAddress.Any,44333, listenOptions =>
                    {
                      listenOptions.UseHttps("Path to SSL certificate","SSL Cert Password");
                        }

                    });
                })
                .UseStartup<Startup>()
                .Build();

I see you are using .NET Core.

.NET Core is hosted in Kestrel instead of the normal IIS and does not support windows authentication. Although you can use HTTP.sys which is a web server implementation in .NET Core and does support windows authentication.

The below code configures the app's web host to use HTTP.sys with Windows authentication.

public class Program
{
    public static void Main(string[] args) => 
        BuildWebHost(args).Run();

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseHttpSys(options =>
            {
                options.Authentication.Schemes = 
                    AuthenticationSchemes.NTLM | AuthenticationSchemes.Negotiate;
                options.Authentication.AllowAnonymous = false;
            })
            .Build();
}

the article explaining this code is here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM