5

I tried to migrate my ASP.NET Core 2.2 project to the newly released ASP.NET Core 3.0 over the weekend.

Everything looked good in the local environment, but after publishing and deploying to IIS, I faced a few issues as it was using the development environment configurations.

I am using Visual Studio 2019 Community Edition version 16.3.0

Upon inspection, I found that the web.config file had the ASPNETCORE_ENVIRONMENT value set to Development, which was causing the issue. It was generated with the web publish even in Release configuration.

I thought it was supposed to be Production? Or did I miss some configuration? I‘ve never faced this issue with any earlier versions of .NET Core.

Now the issue is that if I publish the whole folder again, the issue is likely to come back.

Any solutions or suggestion regarding the root cause of the issue? My Web.config looks like the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <httpRuntime executionTimeout="180" />
  </system.web>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\MyApp.dll" forwardWindowsAuthToken="false" stdoutLogEnabled="false" startupTimeLimit="3600" requestTimeout="23:00:00" hostingModel="InProcess" stdoutLogFile=".\logs\stdout">
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44329" />
        <environmentVariable name="COMPLUS_ForceENC" value="1" />
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Satyajit
  • 2,150
  • 2
  • 15
  • 28
  • Have you checked the project file if it contains any script for adding environment variables to web.config? – Mohsin Mehmood Sep 28 '19 at 14:02
  • I have the same problem. What worked in 2.2 doesn't work in 3.1, because `` is set in web.config. Did you found solution? – Makla Jan 31 '20 at 20:08
  • Solved issue by using environment variable in `.pubxml` file, see https://stackoverflow.com/a/64368721/1662459 – G J Oct 15 '20 at 12:47

1 Answers1

0

Check your csproj file and remove below code if it exists.

<PropertyGroup>
    <EnvironmentName>Development</EnvironmentName>
</PropertyGroup>

Also check the Properties/PublishProfiles/{profilename.pubxml}.This will set the Environment name in web.config when the project is published.

Refer to How to set aspnetcore_environment in publish file?

Ryan
  • 19,118
  • 10
  • 37
  • 53