ASP.NET Core 2.2 Web API Angular. Hosting provider says 500 - Internal Server Error


learner

I'm trying to publish an ASP.NET Core 2.2 Web API and Angular 8 project using SmarterASP.NET, a hosting provider that supports ASP.NET Core. However, I get the following error:

500 Internal Server Error. There is a problem with the resource you are looking for and cannot be displayed.

However, if I start the project locally it works perfectly.

I searched through the internet and various forums and saw this question , another question and this github post .

Here is my Mainmethod:

public class Program
{
    public static void Main(string[] args)
    {
        var host = CreateWebHostBuilder(args).Build();
        WebHost.CreateDefaultBuilder(args)
            .UseSetting(WebHostDefaults.DetailedErrorsKey, "true");

        host.Run();
    }
}

Here is my Configure()class 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();
}

Here is my web.configfile:

<?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-->

I have created the folder logs\stdoutbut the log file is not created.

I'm kind of stuck. Can you say what am I doing wrong?

learner

I have successfully deployed my application! Maybe it will help others.

So my error is:

  1. incorrect web.config. Thanks to the guys at SmarterAsp.Net! This is correct web.config, it shows the detailed error:

    <?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. After web.configthat was fixed, bugs were shown and then detailed. The error is FileNotFoundException. The reason is that Directory.GetCurrentDirectory() it doesn't work correctly.

So I changed the code to:

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. I have added folder wwwrootin my ASP.NET Core 2.2 application and put Angular prod package in it

If anyone needs guidance on how to deploy from Visual Studio

Related


Asp.Net Core 2 Web API 500 Internal Server Error

Anil When I try to access the API through postman, send: localhost:5050/api/Auth/token body: {“ UserName”:“ jouverc”,“ Password”:“ P @ ssw0rd!” } This method: [Produces("application/json")] [Route("api/Auth")] public class AuthController : Controller { #r

Asp.Net Core 2 Web API 500 Internal Server Error

Anil When I try to access the API through postman, send: localhost:5050/api/Auth/token body: {“ UserName”:“ jouverc”,“ Password”:“ P @ ssw0rd!” } This method: [Produces("application/json")] [Route("api/Auth")] public class AuthController : Controller { #r

Asp.Net Core 2 Web API 500 Internal Server Error

Anil When I try to access the API through postman, send: localhost:5050/api/Auth/token body: {“ UserName”:“ jouverc”,“ Password”:“ P @ ssw0rd!” } This method: [Produces("application/json")] [Route("api/Auth")] public class AuthController : Controller { #r

Asp.Net Core 2 Web API 500 Internal Server Error

Anil When I try to access the API through postman, send: localhost:5050/api/Auth/token body: {“ UserName”:“ jouverc”,“ Password”:“ P @ ssw0rd!” } This method: [Produces("application/json")] [Route("api/Auth")] public class AuthController : Controller { #r

Asp.Net Core 2 Web API 500 Internal Server Error

Anil When I try to access the API through postman, send: localhost:5050/api/Auth/token body: {“ UserName”:“ jouverc”,“ Password”:“ P @ ssw0rd!” } This method: [Produces("application/json")] [Route("api/Auth")] public class AuthController : Controller { #r

Asp.Net Core 2 Web API 500 Internal Server Error

Anil When I try to access the API through postman, send: localhost:5050/api/Auth/token Body: {“ UserName”:“ jouverc”,“ Password”:“ P @ ssw0rd!” } This method: [Produces("application/json")] [Route("api/Auth")] public class AuthController : Controller { #r

Asp.Net Core 2 Web API 500 Internal Server Error

Anil When I try to access the API through postman, send: localhost:5050/api/Auth/token Body: {“ UserName”:“ jouverc”,“ Password”:“ P @ ssw0rd!” } This method: [Produces("application/json")] [Route("api/Auth")] public class AuthController : Controller { #r

Asp.Net Core 2 Web API 500 Internal Server Error

Anil When I try to access the API through postman, send: localhost:5050/api/Auth/token Body: {“ UserName”:“ jouverc”,“ Password”:“ P @ ssw0rd!” } This method: [Produces("application/json")] [Route("api/Auth")] public class AuthController : Controller { #r

Asp.Net Core 2 Web API 500 Internal Server Error

Anil When I try to access the API through postman, send: localhost:5050/api/Auth/token Body: {“ UserName”:“ jouverc”,“ Password”:“ P @ ssw0rd!” } This method: [Produces("application/json")] [Route("api/Auth")] public class AuthController : Controller { #r

ASP.NET Core Web API 500 Internal Server Error

Fear I am trying to build an API within the ASP.NET Core framework. I made a basic controller that just returns a string: namespace Dojo_Api.Controllers.Forum { //[Authorize] [Route("api/[controller")] public class ForumController : Controller

ASP.NET Core hosting - 500 Internal Server Error

username I'm trying to publish as an ASP.NET Core project using a hosting provider that supports ASP.NET Core. I get a 500 Internal Server Error, which is pretty common. So I searched on the internet and various forums and checked processPath="%LAUNCHER_PATH%"

ASP.NET Core hosting - 500 Internal Server Error

username I'm trying to publish as an ASP.NET Core project using a hosting provider that supports ASP.NET Core. I get a 500 Internal Server Error, which is pretty common. So I searched on the internet and various forums and checked processPath="%LAUNCHER_PATH%"

ASP.NET Core hosting - 500 Internal Server Error

username I'm trying to publish as an ASP.NET Core project using a hosting provider that supports ASP.NET Core. I get a 500 Internal Server Error, which is pretty common. So I searched on the internet and various forums and checked processPath="%LAUNCHER_PATH%"

ASP.NET Core hosting - 500 Internal Server Error

username I'm trying to publish as an ASP.NET Core project using a hosting provider that supports ASP.NET Core. I get a 500 Internal Server Error, which is pretty common. So I searched on the internet and various forums and checked processPath="%LAUNCHER_PATH%"

ASP.NET Core hosting - 500 Internal Server Error

username I'm trying to publish as an ASP.NET Core project using a hosting provider that supports ASP.NET Core. I get a 500 Internal Server Error, which is pretty common. So I searched on the internet and various forums and checked processPath="%LAUNCHER_PATH%"

ASP.NET Core hosting - 500 Internal Server Error

username I'm trying to publish as an ASP.NET Core project using a hosting provider that supports ASP.NET Core. I get a 500 Internal Server Error, which is pretty common. So I searched on the internet and various forums and checked processPath="%LAUNCHER_PATH%"

500 Internal Server Error when hosting .net Core app in Docker

Avzal I created a test application in .net Core Framework and it works perfectly in development environment. I later published this to a docker container and it worked perfectly because the hosting IP address I declared was listening and I could browse it via

asp.net core application. 500 Internal Server Error

David Edel I uploaded my website to godaddy windows hosted with plesk. All files are uploaded but I get an error: 500 Internal Server Error. There is a problem with the resource you are looking for and cannot be displayed. By researching the problem online, I

ASP.NET Core API-500 Internal Server Error, in production only

facelift I have developed an ASP.NET WebApi application. When I publish and test it to localhost IIS I get this error on one request: Response with status: 500 Internal Server Error for URL: http://localhost/api/COMI/NEW/158/3 web.config: <?xml vers