.net core发布iis遇到的坑

.net core 2.2发布部署iis 访问swagger 404,emm,折腾了很久,要改一下webconfig

原本是这样的

<?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=".\*****.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
    </system.webServer>
  </location>
</configuration>

要加这样的代码,插入到aspNetCore节点,这个节点意思就是开发环境,发布后默认是Production (生产环境) 将swagger禁止了

 <environmentVariables>
     <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>

最后是这样

<?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=".\*****.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout">
      <environmentVariables>
     <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
       </environmentVariables>
     </aspNetCore>
    </system.webServer>
  </location>
</configuration>

3.1版本不需要改

posted @ 2020-03-30 22:33  《赤伶》  阅读(1732)  评论(0编辑  收藏  举报