c# - ASP.NET Core 2.2 Web API 角。托管服务提供商说 500 - 内部服务器错误
问题描述
我正在尝试使用支持 ASP.NET Core 的托管服务提供商 SmarterASP.NET 发布 ASP.NET Core 2.2 Web API 和 Angular 8 项目。但是,我收到以下错误:
500内部服务器错误。您要查找的资源有问题,无法显示。
但是,如果我在本地启动该项目,它会完美运行。
我通过互联网和各种论坛搜索,看到这个问题,另一个问题和这个 github 帖子。
这是我的Main
方法:
public class Program
{
public static void Main(string[] args)
{
var host = CreateWebHostBuilder(args).Build();
WebHost.CreateDefaultBuilder(args)
.UseSetting(WebHostDefaults.DetailedErrorsKey, "true");
host.Run();
}
}
这是我Configure()
的StartUp
班级:
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
IServiceProvider provider)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404 &&
!Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/index.html";
await next();
}
});
app.ConfigureCustomExceptionMiddleware();
app.UseCors("ApiCorsPolicy");
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"StaticFiles")),
RequestPath = new PathString("/StaticFiles")
});
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseMvc();
app.UseDeveloperExceptionPage();
}
这是我的web.config
文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<httpErrors errorMode="Detailed" />
<aspNetCore processPath="dotnet">
<environmentVariables>
<environmentVariable name="ASPNETCORE_DETAILEDERRORS" value="true" />
</environmentVariables>
</aspNetCore>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2"
resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\fooappl.dll" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
<!--ProjectGuid: 25e0e882-c3ff-4f8d-98cc-f26a692fa019-->
我已经创建了文件夹logs\stdout
,但是没有创建日志文件。
我有点卡住了。你能说我做错了什么吗?
解决方案
我遇到了类似的问题,我通过在配置文件中提供 dotnet exe 的完整路径来解决这个问题。根据您的服务器路径更新进程路径:
<aspNetCore processPath="C:\Program Files\dotnet\dotnet.exe" arguments=".\fooappl.dll" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
试一次!
推荐阅读
- tensorflow - Keras 如何处理单元格和隐藏状态(RNN、LSTM)的初始值以进行推理?
- javascript - Javascript 图像大小检查(字节)
- c++ - 与 std::system_clock 相比,std::steady_clock 是否会产生开销?
- javascript - 使用 Async/Await 调用 Async 函数为对象中的键赋值
- mysql - 带有 Json_value 的 T-sql 语法不正确
- javascript - index.php 与 index.html
- python - 用字典值替换 Pandas Dataframe 中的部分字符串
- arrays - 如何加粗数组的第一个单词?
- django - 如何使用choicefield的实例在django中搜索对象?
- mysql - MySQL是否可以根据时间序列计算平均时间?