我们的托管部门不愿意允许运行Kestrel的ASP.NET核心托管或甚至安装ASP.NET Core Server Hosting Bundle(AspNetCoreModule)。在没有Kestrel的IIS中托管ASP.NET核心
在这种情况下,有没有其他选择允许ASP.NET核心?
环境:带有最新IIS和.NET 4.6.2的Windows Server 2012 R2。
这是一个共享主机环境,并且应用程序必须在IIS中运行。
我们的托管部门不愿意允许运行Kestrel的ASP.NET核心托管或甚至安装ASP.NET Core Server Hosting Bundle(AspNetCoreModule)。在没有Kestrel的IIS中托管ASP.NET核心
在这种情况下,有没有其他选择允许ASP.NET核心?
环境:带有最新IIS和.NET 4.6.2的Windows Server 2012 R2。
这是一个共享主机环境,并且应用程序必须在IIS中运行。
是的,您可以使用WebListener Web服务器而不是Kestrel。 WebListener只能在Windows平台上运行,但由于这是您正在运行的地方,因此这是您的选择。
但是,WebListener不依赖IIS作为反向代理,实际上WebListener不能与IIS或IIS Express一起使用,因为它与ASP.NET Core Module不兼容。但它确实为您提供了一个用于在Windows上托管ASP.NET Core的非Kestrel选项。
您可以了解更多有关在这里:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/weblistener
如果你必须在IIS托管和你不希望使用红隼,你在Windows上运行,那么有没有选项。在Windows上,您可以使用没有IIS的WebListener进行托管,也可以将使用IIS作为反向代理的Kestrel托管。这些是目前Windows上的唯一两个选项。
通过使用OWIN,您实际上可以在工作进程中的IIS中运行ASP.NET Core(因此不使用ASP.NET核心模块)。
这是可能的,因为ASP.NET Core can be hosted on an OWIN server和IIS can be made an OWIN Server。
看看下面的OWIN中间件,它展示了如何在IIS上运行ASP.NET Core。有关更完整的示例,请参阅此要点:https://gist.github.com/oliverhanappi/3720641004576c90407eb3803490d1ce。
public class AspNetCoreOwinMiddleware<TAspNetCoreStartup> : OwinMiddleware, IServer
where TAspNetCoreStartup : class
{
private readonly IWebHost _webHost;
private Func<IOwinContext, Task> _appFunc;
IFeatureCollection IServer.Features { get; } = new FeatureCollection();
public AspNetCoreOwinMiddleware(OwinMiddleware next, IAppBuilder app)
: base(next)
{
var appProperties = new AppProperties(app.Properties);
if (appProperties.OnAppDisposing != default(CancellationToken))
appProperties.OnAppDisposing.Register(Dispose);
_webHost = new WebHostBuilder()
.ConfigureServices(s => s.AddSingleton<IServer>(this))
.UseStartup<TAspNetCoreStartup>()
.Build();
_webHost.Start();
}
void IServer.Start<TContext>(IHttpApplication<TContext> application)
{
_appFunc = async owinContext =>
{
var features = new FeatureCollection(new OwinFeatureCollection(owinContext.Environment));
var context = application.CreateContext(features);
try
{
await application.ProcessRequestAsync(context);
application.DisposeContext(context, null);
}
catch (Exception ex)
{
application.DisposeContext(context, ex);
throw;
}
};
}
public override Task Invoke(IOwinContext context)
{
if (_appFunc == null)
throw new InvalidOperationException("ASP.NET Core Web Host not started.");
return _appFunc(context);
}
public void Dispose()
{
_webHost.Dispose();
}
}
我已经成功地做到了这一点,但是我确实需要将内容类型设置为“”,以便AspNetCore不会感到困惑,并将owin实现默认的文本/ html返回给406。 –
看起来OP想要将他们的Core应用程序作为Web应用程序部署在共享主机环境中。他们无法控制Web服务器。他们不能只部署一个控制台应用程序,它自己绑定到端口80. – CodeCaster
是的CodeCaster是正确的,我错过了这个信息,但它必须包含在IIS共享主机 – DavWEB
好吧,我想我们必须坚持ASP.NET非 - 核心现在.. – DavWEB