.Net Core 应用程序在启动时使用进程外托管模型卡住挂起/加载
我有一个 3.1 net core Web api,我必须从进程内托管模型切换到进程外托管模型,因为我的托管环境只有一个应用程序池,而该池中运行着两个应用程序。由于与应用程序池相关的进程内限制,我不得不将两个应用程序切换到进程外。
在我的本地环境(从 vs studio 运行它时)和托管环境上,Web api 在启动时都会卡住/加载/挂起。唯一的区别是,在托管环境中,一段时间后,我收到“HTTP Error 502.5 ANCM Out-Of-Process Startup Failure”类型的错误。
经过一些研究后,我发现大多数错误是由“Program.cs”类中的某些代码引起的。确实如此。注释掉以下代码部分后,它就可以工作了。
public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration) =>
Host.CreateDefaultBuilder(args)
//.ConfigureAppConfiguration(builder =>
//{
// builder.Sources.Clear();
// builder.AddConfiguration(configuration);
//})
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
发生的情况是,我清除了默认配置,以便我只能在“Main”方法中插入显式定义的配置(至少这是我在编写该代码时想要做的)。
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json")
.AddUserSecrets(Assembly.GetExecutingAssembly())
.AddEnvironmentVariables()
.Build();
不知何故,清除默认配置会导致应用程序无法在进程外托管模型中工作,我真的很想知道原因。
I have a 3.1 net core web api which I had to switch from in process to out of process hosting model because my hosting environment has only one application pool and I have two applications running in that pool. Because of the in process restriction related to the application pool I had to switch both apps to out of process.
The web api gets stuck/loading/hanging on startup both on my local environment (when running it from vs studio) and on the hosting environment. The only difference is that on the hosted environment, after a while, I get a "HTTP Error 502.5 ANCM Out-Of-Process Startup Failure" type error.
After doing some research I've found out that most of this errors are caused by some code in the "Program.cs" class. And indeed it was. After commenting out the following code portion it works.
public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration) =>
Host.CreateDefaultBuilder(args)
//.ConfigureAppConfiguration(builder =>
//{
// builder.Sources.Clear();
// builder.AddConfiguration(configuration);
//})
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
What happens is that I clear the default configurations so that I can only insert my explicitly defined ones in the "Main" method (at least this is what I think I wanted to do at the time I wrote that code).
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile(quot;appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json")
.AddUserSecrets(Assembly.GetExecutingAssembly())
.AddEnvironmentVariables()
.Build();
Somehow, clearing the default configurations causes the app to not work in the out of process hosting model and I really wanted to know why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论