发布后的项目打开swagger

使用netcore做为纯后端提供api已经变得愈来愈频繁,swagger也成为不少人的选择。一般会在代码中限制ASPNETCORE_ENVIRONMENT为Production时关闭swagger。可是每每咱们须要将api发布到本地iis调试或供他人使用时,swagger将会被禁止。发布后项目每每默认为Production环境,将其修改成Development便可解决。web

解决方法

打开发布到iis的文件夹下的web.config文件,添加如下代码:后端

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

修改后的web.config结构大体以下:api

<?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">
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
    </aspNetCore>
    </system.webServer>
  </location>
</configuration>
相关文章
相关标签/搜索