c# - ASP.NET Core 3.1 - HTTP 错误 500.30 - ANCM 进程内启动失败
问题描述
我正在使用 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 个错误,但我不知道出了什么问题。错误:
物理根目录为“我的应用程序文件夹”的应用程序“/LM/W3SVC/2/ROOT”已从 Program.Main 退出,退出代码为“0”。捕获的 stdout 和 stderr 日志的前 30KB 字符:程序启动
具有物理根目录“我的应用程序文件夹”的应用程序“/LM/W3SVC/2/ROOT”无法加载 coreclr。异常消息:CLR 工作线程过早退出
谢谢你的时间
解决方案
以下步骤对我有用:
- 确保应用程序池标识为托管代码
- 确保 IIS_IUSRS 对网站文件夹具有权限
- 确保发布时在解决方案中创建日志文件夹。如果它不可用,我们还可以将 stdoutLogEnabled 设置为 true,正如 Alexander Protto 在另一个答案中所指出的那样。这一步是我的问题。
- 确保目标运行时正确。如果不正确,则错误将有所不同。
- 确保将 CreateDefaultBuilder(args) 添加到 startup.cs。这类似于Hamit发布的答案。
推荐阅读
- c++ - vs代码访问被拒绝cpp
- double - 在 GPU 上,是否可以通过结合双精度和浮点运算来获得更多的触发器?
- python - 从 .htb 文件中删除前 3 列
- powerbi - 基于日期周期和返回日期的切片器的 DAX 度量
- spring-boot - Keycloak 管理员 cli 超时
- sql - 添加另一个表ORACLE SQL时Sum值太大
- javascript - 使用 JS 获取表单数据到 URL
- java - 有没有办法在同一方法中传递不同(但特定)类型的对象,并根据对象的类型有不同的处理方式
- angular - Angular AG-GRID:尝试在按钮单击时展开 ag-grid 行。但什么也没有发生
- reactjs - React Firebase 防止 axios 中的令牌过期