Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web.config is invalid after publishing my Core 2.2 project on the server

I have a project written using C# on the top of Asp.NET Core 2.2 framework.

I was able to publish it to my VPS. But, when I try to access the website I get the following error

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Here is the content of the web.config file located in the root

<?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=".\ProjectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: 47b26df0-8a01-4d75-9549-3a98654550a3-->

The web.config file was published via Visual Studio along with the rest of my files. But I don't see web.config file in my solution.

This file seems to be invalid. How can I fix the web.config file?

If I remove the web.config file and add index.html page the site work. It sounds to me that web.config the file is invalid for some reason.

Updated I am able to run the application using the command line. using the command line, I did the following

  1. I change directory into the root of my website (i.e cd C:\inetpub\wwwroot\ProjectName)
  2. I execute the following command dotnet ProjectName.dll
  3. 10 seconds later, I got some information that the app is running and it showed me the URL it is listing to. In my case it was http://localhost:5000
  4. O used the browser to browser http://localhost:5000 and it works fine.

But when I access it using the domain name, I still get Http Error 500.19 as stated above.

like image 492
Junior Avatar asked Oct 28 '25 09:10

Junior


1 Answers

As discussed in comments

Install AspnetCore module in iis

Setup ASPNETCORE_ENVIRONMENT to production in your environment or setup in web.config.

<aspNetCore processPath="dotnet"
      arguments=".\MyApp.dll"
      stdoutLogEnabled="false"
      stdoutLogFile="\\?\%home%\LogFiles\stdout"
      hostingModel="InProcess">
  <environmentVariables>
    <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
  </environmentVariables>
</aspNetCore>
like image 54
Vova Bilyachat Avatar answered Oct 29 '25 23:10

Vova Bilyachat