使用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>