gpt4 book ai didi

c# - ASP.NET Core 3.1 - HTTP 错误 500.30 - ANCM 进程内启动失败

转载 作者:行者123 更新时间:2023-12-03 16:11:18 35 4
gpt4 key购买 nike

我正在使用 3.1 版本配置 net core web api。我已经在这里检查了这个问题,但没有一个答案适用于我的案例。

我尝试使用 net core ver 3.1 配置 web api。另一个具有类似配置和相同版本软件包的应用程序也可以在我的电脑上使用相同的 iis express。

这是我的 Startup.cs

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
readonly string AllowSpecificOrigins = "_allowSpecificOrigins";


public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(AllowSpecificOrigins,
builder =>
{
builder.AllowCredentials().AllowAnyMethod().AllowAnyHeader().WithOrigins("http://localhost:4200");
});
});

services.AddControllers()
.AddNewtonsoftJson();

services.AddScoped<IAccountRepository, AccountRepository>();
services.AddScoped<IDocsRepository, DocsRepository>();

services.AddDbContext<LibContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("LibraryDatabase"), x => x.UseNetTopologySuite()));

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = AuthOptions.ISSUER,
ValidateAudience = true,
ValidAudience = AuthOptions.AUDIENCE,
ValidateLifetime = true,
IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey(),
ValidateIssuerSigningKey = true
};
});
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
//password settings
options.Password.RequiredLength = 8;
options.Password.RequireNonAlphanumeric = false;

options.User.RequireUniqueEmail = true;

//lockout settings
options.Lockout.AllowedForNewUsers = true;
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
options.Lockout.MaxFailedAccessAttempts = 5;
})
.AddEntityFrameworkStores<LibContext>()
.AddUserManager<UserManager<ApplicationUser>>()
.AddDefaultTokenProviders();

services.AddSignalR();

}


public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(AllowSpecificOrigins); //DEV MODE!
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Library")),
RequestPath = new PathString("/Library")
});
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}

好像我的 appsettings.json 中没有错别字
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"LibraryDatabase": "Host=localhost;Port=5432;Database=librarydb;Username=postgres;Password=mypasshere"
}
}

我的 app.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="Library\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="2.2.0" />
<PackageReference Include="ProjNET4GeoAPI" Version="1.4.1" />
</ItemGroup>


</Project>

事件查看器抛出 2 个错误,但我无法弄清楚出了什么问题。错误:

Application '/LM/W3SVC/2/ROOT' with physical root 'my app folder' has exited from Program.Main with exit code = '0'. First 30KB characters of captured stdout and stderr logs: Programm starts

Application '/LM/W3SVC/2/ROOT' with physical root 'my app folder' failed to load coreclr. Exception message: CLR worker thread exited prematurely



谢谢你的时间

最佳答案

好的,我想我找到了答案。它在我的情况下有效!

程序 main.cs 的有趣问题不是这种配置,它们表现良好。
有几种情况会发生此错误

案例1- 从其他核心版本迁移到 .net core 3.1 时。使用 红隼 与 IHostBuilder。不要用这个

            Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
//..
})
.UseStartup<Startup>();
})
.Build();

而是使用这种风格。 ( CreateHostBuilder )
            var host = CreateHostBuilder(args).UseServiceProviderFactory(new AutofacServiceProviderFactory()).Build();
host.Run();

//..
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
serverOptions.Limits.MaxConcurrentConnections = 100;
serverOptions.Limits.MaxConcurrentUpgradedConnections = 100;
serverOptions.Limits.MaxRequestBodySize = 10 * 1024;
serverOptions.Limits.MinRequestBodyDataRate =
new MinDataRate(bytesPerSecond: 100,
gracePeriod: TimeSpan.FromSeconds(10));
serverOptions.Limits.MinResponseDataRate =
new MinDataRate(bytesPerSecond: 100,
gracePeriod: TimeSpan.FromSeconds(10));
serverOptions.Limits.KeepAliveTimeout =
TimeSpan.FromMinutes(2);
serverOptions.Limits.RequestHeadersTimeout =
TimeSpan.FromMinutes(1);
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
});

案例2- Program.cs 找不到 Logger 文件或配置文件。它可能无法达到文件夹文件权限等。在主函数中使用 try catch 检查它。

案例3- InProcess 模式没有或未配置 AspNetCoreModuleV2

通常 1 是此错误的正确情况,但对 2 和 3 感兴趣

关于c# - ASP.NET Core 3.1 - HTTP 错误 500.30 - ANCM 进程内启动失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61678757/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com