0

I am trying to figure out this bug for a week but I still cant find the error.

System I am currently running is Linux Ubuntu 16.04

I have set everything to production in launchSettings.json

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:51754/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    },
    "FilmerCore": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      },
      "applicationUrl": "http://localhost:51755"
    }
  }
}

And this is my web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\FilmerCore.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
    <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>

</configuration>
<!--ProjectGuid: 5be3ea4c-66c2-42b0-8583-29c6bf415674-->

Aslo I am using nginx as a reverse proxy. The main config is this

[Unit]
    Description=Filmer - .NET movie platform

    [Service]
    WorkingDirectory=/var/aspnetcore/filmer
    ExecStart=/usr/bin/dotnet /var/aspnetcore/filmer/FilmerCore.dll
    Restart=always
    RestartSec=10                                          # Restart service after 10 seconds if dotnet service crashes
    SyslogIdentifier=filmer
    User=www-data
    Environment=ASPNETCORE_ENVIRONMENT=Development 

    [Install]
    WantedBy=multi-user.target

Error that is showing up

1 Answer 1

2

Of course it won't work, because you didn't set the environment variable.

  • web.config is only there for IIS. nginx can't do anything with it.
  • launchSettings.json is only used for Visual Studio to launch your project when you hit F5.

You must look into ngnix documentation on how to set environment variables or set a global variable in the shell (which will be valid for all applications on the server) like export ASPNETCORE_ENVIRONMENT=Development.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply. I have forgotten to add this, This is running on the background. I am using Nginx only as a reverse prox server. I have set in /etc/systemd/system/kestrel-filmer.service Environment=ASPNETCORE_ENVIRONMENT=Production
@DominikVit you need to set ASPNETCORE_ENVIRONMENT for ASP.NET Core process, not for Nginx process. As @Tseng said, you need to set up it globally or, as an option, you may pass environment name as the argument to you .net core application. See next SO question for details: run .net core application in development from the command line
Thanks for your reply. I have tried it but without any success. It is doing still the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.