首页 > 解决方案 > 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,但是没有创建日志文件。

我有点卡住了。你能说我做错了什么吗?

标签: c#angularasp.net-coreasp.net-core-webapiasp.net-core-2.2

解决方案


我遇到了类似的问题,我通过在配置文件中提供 dotnet exe 的完整路径来解决这个问题。根据您的服务器路径更新进程路径:

<aspNetCore processPath="C:\Program Files\dotnet\dotnet.exe" arguments=".\fooappl.dll" stdoutLogEnabled="true" 
      stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />

试一次!


推荐阅读