Forum Discussion

saifiqbal10p's avatar
saifiqbal10p
Occasional Visitor
2 years ago

Swagger UI not loading on iis when using handlers

Hello, I have a application deployed on iis build on .net 6 and angular. SPA has been served from the same url with url rewriting applied on web.config.

Application works fine. But i am unable to browse swagger ui with the url /swagger/index.html it throws 404. If i remove the static file handler swagger starts working but the handler is required to server spa file index.html and other static files.

 

I am adding swagger configuration from startup.cs file and web.config for your reference.  Any help will be very much appreciated.

 

swagger configuration:

 

app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "API");
options.DocumentTitle = "Smart Procedures UI";
});

 

Web config:

 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="StaticFileModuleHtml" path="*.htm*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="StaticFileModuleSvg" path="*.svg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="StaticFileModuleJson" path="*.json" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="StaticFileModuleJs" path="*.js" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="StaticFileModuleCss" path="*.css" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="StaticFileModuleJpeg" path="*.jpeg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="StaticFileModuleJpg" path="*.jpg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="StaticFileModulePng" path="*.png" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="StaticFileModuleGif" path="*.gif" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Exelon.Api.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<rewrite>
<outboundRules rewriteBeforeCache="true">
<rule name="Remove Server header">
<match serverVariable="RESPONSE_Server" pattern=".+" />
<action type="Rewrite" value="" />
</rule>
</outboundRules>
<rules>
<clear />
<rule name="HttpToHttps" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="SignalRProxyRule" stopProcessing="true">
<match url="notificationhub(/.*)*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{CACHE_URL}" pattern="^(.+)://" />
</conditions>
<action type="Rewrite" url="http://localhost:8082/notificationhub{R:1}" logRewrittenUrl="true" />
</rule>
<rule name="AppleAppSite" stopProcessing="true">
<match url="^apple-app-site-association$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="apple-app-site-association" />
</rule>
<rule name="Hanfire-Rule" stopProcessing="true">
<match url="hangfire" />
<action type="None" />
</rule>
<rule name="wwwroot-static" stopProcessing="true">
<match url="([\S]+[.](html|htm|svg|json|js|css|png|gif|jpg|jpeg|api/v1))" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="/swagger/.*" negate="true" />
</conditions>
<action type="Rewrite" url="static/{R:1}" />
</rule>
<rule name="Assets-Rule" stopProcessing="true">
<match url="assets\/*|/*.js|/*.css|/*.map|/*.woff2|/*.woff|/*.svg|/*.ttf|/*.eot|index.html" />
<action type="None" />
</rule>
<rule name="empty-root-index" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="static/index.html" />
</rule>
<rule name="AngularJS-Html5-Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/api/" negate="true" />
<add input="{REQUEST_URI}" pattern="/swagger/.*" negate="true" />
</conditions>
<action type="Rewrite" url="static/index.html" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
</configuration>

No RepliesBe the first to reply