![](/img/trans.png)
[英]HTTP Error 500.30 - ANCM In-Process Start Failure Asp.net-Core 3.1
[英]ASP.NET Core 3.1 - HTTP Error 500.30 - ANCM In-Process Start Failure
我尝试使用网络核心版本 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 个错误,但我不知道出了什么问题。 错误:
物理根目录为“我的应用程序文件夹”的应用程序“/LM/W3SVC/2/ROOT”已从 Program.Main 退出,退出代码为“0”。 捕获的 stdout 和 stderr 日志的前 30KB 字符:程序启动
具有物理根目录“我的应用程序文件夹”的应用程序“/LM/W3SVC/2/ROOT”无法加载 coreclr。 异常消息:CLR 工作线程过早退出
好的,我想我找到了答案。 它在我的情况下有效!
与此配置无关的程序 main.cs 有趣的问题,它们表现得很好。 有几种情况会发生此错误
案例 1- 从其他内核版本迁移到.net内核 3.1 时。 将红隼与 IHostBuilder 一起使用。 不要使用这个
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
//..
})
.UseStartup<Startup>();
})
.Build();
而是使用这种风格。 (创建主机生成器)
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 文件或配置文件。 它可能无法访问文件夹文件权限等。请通过主 function 中的 try catch 进行检查。
案例 3- InProcess 模式没有或未配置 AspNetCoreModuleV2
通常 1 是此错误的正确情况,但对 2 和 3 感兴趣
以下步骤对我有用:
我有同样的问题并尝试了一切。 最后,通过修复appsetting.json文件结构解决了这个问题。
我变了
stdoutLogEnabled="false"
至
stdoutLogEnabled="true",
然后错误消息告诉我错误在哪里。
另外,请务必检查“appsetting.json”中的连接字符串。 在我的情况下,忘记向数据源添加转义字符。 所以,拥有服务器名称的正确方法是\\MSSQLSERVER ,但我有\\MSSQLSERVER 。 只是一个小错误,但花了一些时间才弄清楚。
非常感谢。 我遇到了同样的问题,我将 AspNetCoreHostingModel 键和值添加到我的 VS 项目中,它成功了。 我正在寻找我拿它的地方,但我找不到它,但它在 Stack Overflow 的这里。 所以,感谢原作者!!!
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<SignAssembly>false</SignAssembly>
<OutputType>Exe</OutputType>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>
正如其他用户所提到的,我尝试并工作的其中一件事是将托管 model 更改为 OutOfProcess。 但是,这并不总是有效,如果您配置了 swagger,我发现了一些相当奇怪的技巧,手动将“项目”.xml 文件复制到解决方案的部署根目录。
但是,后者应该通过检查您的事件查看器来备份,并且您有此错误 System.IO.FileNotFoundException
在我的情况下,将应用程序池帐户从 NetworkService 更改为 LocalSystem 解决了这个问题。
在寻找我的问题的解决方案时,我遇到了这篇文章。 我收到与您完全相同的错误,基本上是因为我还尝试使用网络位置的 PhysicalFileProvider 提供 static 文件。 在我的情况下,当我在 localhost 中调试时它运行良好......但在部署时我也得到了你的错误。 我认为这条线是导致您的具体问题的原因:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Library")),
RequestPath = new PathString("/Library")
});
我会尝试注释掉该块以查看错误是否仍然存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.