我在将.net core 5.0 Web API托管在IIS时遇到问题,因此我决定创建一个基本的即装即用版本(WeatherForecast)。同样,这在IIS上也不起作用(因此,我认为这不是我的代码)。我已经安装了.Net Core Hosting Bundle 5.0(V5.0.2),并重新启动了IIS(net stop was /y
,net start w3svc
)。
我的网站托管在https://authdev.XXXXXXXX.net/api/weatherforecast(其中XXXXXXXX.net在我的内部网络上)。该服务器是Microsoft Hyper-V Server2019。我有一个单独的应用程序池,在集成管道模式下,.Net CLR版本设置为“无托管代码”。我的网站设置了适当的绑定,并且配置正确。我已经通过创建一个.Net Core 5.0 MVC网站(开箱即用)从该服务器远程工作来确认这一点。我在进程外模式下得到404(并且相同的URL在本地与明显的服务器URL更改一起工作)。我在某一阶段添加了日志记录信息,并发现public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Startup.cs中的方法未命中。
我认为此消息表明我的托管环境已正确配置,但我的Web API(开箱即用)存在错误。
Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.UseContentRoot(Directory.GetCurrentDirectory())
.UseKestrel()
.UseIISIntegration()
.UseStartup<Startup>();
});
}
web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\WebApplication4.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 9f838b88-2902-4f1d-96d5-468aa0449fb0-->
启动文件
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
我尝试在进程内和进程外模式下运行此命令
进程内日志
crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
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.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
Unhandled 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.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at WebApplication4.Program.Main(String[] args) in C:\Working\dev\sandbox\WebApplication4\WebApplication4\Program.cs:line 17
进程外日志
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://127.0.0.1:43593
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: e:\websites\auth-api
您确定要以独立包装发布吗?因为如果没有,您的配置应如下所示:
<aspNetCore processPath="dotnet"
arguments=".\WebApplication16.dll"
stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout"
hostingModel="inprocess" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句