Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Net Core 2.0正在查找appsettings.Production.json_Asp.net_Asp.net Core_.net Core_Asp.net Core 2.0 - Fatal编程技术网

Asp.net Net Core 2.0正在查找appsettings.Production.json

Asp.net Net Core 2.0正在查找appsettings.Production.json,asp.net,asp.net-core,.net-core,asp.net-core-2.0,Asp.net,Asp.net Core,.net Core,Asp.net Core 2.0,我已经创建了两个这样的.net core 2 web应用程序,在此之前没有任何问题 在IISExpress下运行local时运行正常,但当我将调试版本部署到服务器上的IIS文件夹时,我遇到了问题 当我读取配置条目时,找不到它: _config["MySettings:MyName"]; 文件内容: appsettings.Development.json { "Logging": { "IncludeScopes": false, "LogLevel": { "

我已经创建了两个这样的.net core 2 web应用程序,在此之前没有任何问题

在IISExpress下运行local时运行正常,但当我将调试版本部署到服务器上的IIS文件夹时,我遇到了问题

当我读取配置条目时,找不到它:

_config["MySettings:MyName"];
文件内容:

appsettings.Development.json

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Trace",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "MySettings": {
    "MyName": "JohnDoe"
  }
}
{
  "Logging": {
    "IncludeScopes": false,
    "Debug": {
      "LogLevel": {
        "Default": "Trace"
      }
    },
    "Console": {
      "LogLevel": {
        "Default": "Warning"
      }
    }
  }
}
{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:60668/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/security",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WebApi.ViewerSecurity": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/security",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:60669/"
    }
  }
}
appsettings.json

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Trace",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "MySettings": {
    "MyName": "JohnDoe"
  }
}
{
  "Logging": {
    "IncludeScopes": false,
    "Debug": {
      "LogLevel": {
        "Default": "Trace"
      }
    },
    "Console": {
      "LogLevel": {
        "Default": "Warning"
      }
    }
  }
}
{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:60668/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/security",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WebApi.ViewerSecurity": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/security",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:60669/"
    }
  }
}
launchSetting.json

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Trace",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "MySettings": {
    "MyName": "JohnDoe"
  }
}
{
  "Logging": {
    "IncludeScopes": false,
    "Debug": {
      "LogLevel": {
        "Default": "Trace"
      }
    },
    "Console": {
      "LogLevel": {
        "Default": "Warning"
      }
    }
  }
}
{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:60668/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/security",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WebApi.ViewerSecurity": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/security",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:60669/"
    }
  }
}
如果我复制appsettings.Development.json并重命名为appsettings.Production.json,它就会工作

我更改了prod文件中“MyName”的值并将其记录下来。是的,从appsettings.Production.json读取


如何以及为什么?没有在任何地方定义生产。

默认的
ConfigurationBuilder
正在查找
appsettings..json
文件,因此根据您使用的环境,此文件的名称会发生更改。当您在IIS Express中时,您处于
开发中
,当您部署应用程序时,您的环境是
生产环境
。这就是为什么需要
appsettings.Production.json


调试时,有一个名为
ASPNETCORE\u Environment
的环境变量被设置为
Development
,在部署中未设置
ASPNETCORE\u Environment
,默认值为
Production

,将环境更改为Production。我看不到在任何地方设置了任何环境变量。如果未设置
ASPNETCORE\u ENVIRONMENT
,它将默认为
Production
。这有文档记录吗?@ginalster有,这是链接