.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" />