.net core 部署之后swagger 404解决方案

.net core项目部署到iis,托管设置了无托管,访问swagger还是404;

排查原因为代码里配置了

 if (env.IsDevelopment())
    {
          app.UseSwagger();
          app.UseSwaggerUI();
     }

只有开发环境才显示swagger;

解决办法:

1.去除这个if判断,重新发布即可;

2.或者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=".\MiMaDao.SCRM.Host.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" >
 <environmentVariables>
            <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

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

上一篇:vue项目遇到布署服务器后刷新404问题解决方案


下一篇:tomcat修改端口以及启动项目404