在IIS中托管RestAPI [英] Host RestAPI inside IIS
问题描述
我有一个非常简单的.NET WebApi应用程序,我正在尝试将其托管在IIS中.遵循了MS网站上有关此问题的所有说明. 这是它的启动方法.
I have a rather simple .NET WebApi application which I'm trying to host inside IIS. Followed all of the instructions from MS site about this. here is the startup method for it.
public static void Main(string[] args)
{
var host = WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
我将应用程序池配置为不使用任何托管代码,但是在日志中仍然出现此错误
I configured the Application pool to not use any managed code but I'm getting still this error in logs
Application startup exception: System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6]
我没有任何想法可能是错误的. 有什么建议?
I'm out of any ideas what can be wrong. Any suggestions?
使用.NET Core 2.2
Using .NET Core 2.2
推荐答案
对于InProcess
,它使用IISHttpServer
.
对于您的代码,您正在配置使用out-of-process
的UseKestrel()
.
For your code, you are configuring UseKestrel()
which uses out-of-process
.
要获取解决方案,请除去.UseKestrel()
行.
For solution, remove the .UseKestrel()
line.
public static void Main(string[] args)
{
var host = WebHost.CreateDefaultBuilder(args)
//.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
For more details, refer ASP.NET Core Module.
这篇关于在IIS中托管RestAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!