[英]How to add NTLM auth to .net core when app could be self hosted or IIS
我有一个.net核心应用程序,需要使用NTLM身份验证。 如果我使用包Microsoft.AspNetCore.Server.HttpSys
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseHttpSys(options =>{
options.Authentication.Schemes = AuthenticationSchemes.NTLM | AuthenticationSchemes.Negotiate;
options.Authentication.AllowAnonymous = false;
}).Build()
如果我自行托管,它将很好用,但是如果将其部署在IIS上,则会崩溃。
如果不使用它,而使用IIS设置提供Windows身份验证,则存在相同的区别,如果我需要运行自托管,它将崩溃。
无论如何,要使一个可执行文件在两种情况下都适用?
是的,但是这种解决方案有点阴暗。
有一个设置指示IIS是否正在提供身份验证。 但是该设置由标记为internal的常量键入。 因此,如果您对魔术字符串"IIS_HTTPAUTH"
硬编码,则可以访问它。
var webhost = WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
//If not hosted by IIS for auth
if (String.IsNullOrEmpty(webhost.GetSetting("IIS_HTTPAUTH"))) {
webhost = webhost.UseHttpSys(options => {
options.Authentication.Schemes = AuthenticationSchemes.NTLM | AuthenticationSchemes.Negotiate;
options.Authentication.AllowAnonymous = false;
});
}
return webhost.Build();
截至.netcore2.0.X当前
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.