簡體   English   中英

ASP.NET 內核 2.2 Web API ZC31C335EF37283C451B18BA0DD317DE1。 托管服務提供商說 500 - 內部服務器錯誤

[英]ASP.NET Core 2.2 Web API Angular. Hosting provider says 500 - Internal server error

I am trying to publish ASP.NET Core 2.2 Web API and Angular 8 project with a hosting provider SmarterASP.NET that supports ASP.NET Core. 但是,我收到以下錯誤:

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();
    }
}

這是我的StartUp class 的Configure()

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" />

試一次!

我已經成功部署了我的應用程序。 也許它會對其他人有所幫助。

所以我的錯誤是:

  1. 不正確web.config 感謝 SmarterAsp.Net 的人! 這是正確的web.config顯示詳細錯誤:

     <?xml version="1.0" encoding="utf-8"?> <configuration> <location path="." inheritInChildApplications="false"> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\yourAppl.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" > <environmentVariables> <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> </environmentVariables> </aspNetCore> </system.webServer> </location> </configuration> <:--ProjectGuid: 25e0e882-c3ff-4f8d-98cc-f26a692fa019-->
  2. web.config后,會顯示詳細錯誤。 錯誤是FileNotFoundException 原因是Directory.GetCurrentDirectory()工作不正確。

所以我將代碼更改為:

private IHostingEnvironment _env;

public Startup(IConfiguration configuration, IHostingEnvironment env)
{
    Configuration = configuration;
    _env = env;
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider provider)
{   
    // The other code is omitted for the brevity
    app.UseStaticFiles(new StaticFileOptions()
    {                
        FileProvider = new PhysicalFileProvider(Path.Combine(_env.ContentRootPath, @"StaticFiles")),
        RequestPath = new PathString(Path.Combine(_env.ContentRootPath, "/StaticFiles"))
    });
}
  1. 我在 ASP.NET Core 2.2 應用程序中添加了文件夾wwwroot ,並將 Angular 產品包放入其中

如果有人需要如何從 Visual Studio 部署的指南

嘗試從 web.config 文件中刪除 hostingModel="InProcess"。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM