简体   繁体   中英

Swagger / Swashbuckle works in IIS Express but not IIS

I installed Swashbuckle into my web api Application using the following guide: http://bitoftech.net/2014/08/25/asp-net-web-api-documentation-using-swagger/

It works great when I run it on my local IIS express / Cassini installation and point my browser at http://localhost:59988/swagger/

However, it does not appear to work when accessing the application through IIS8.5, for example at http://my.localhost/swagger/

I get redirected to /swagger/ui/index/ which throws the exception

{"Message":"An error has occurred.","ExceptionMessage":"Mapping not found - index/","ExceptionType":"Swashbuckle.SwaggerUi.AssetNotFound","StackTrace":" at Swashbuckle.SwaggerUi.EmbeddedAssetProvider.GetAsset(String rootUrl, String path)\\r\\n at Swashbuckle.Application.SwaggerUiHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)"}

the problem seems to arise from the fact that IIS redirects me and appends a trailing slash on the end of the url (that's also what the error message says.)

I have

question: why does IIS add the trailing slash to the url and what are my options to get swashbuckle to work in IIS?

Had the same problem: I had tried changing a couple of IIS settings and Swagger stopped working, and reverting the settings did not help.

I did this to get it to work again:

  1. Open C:\\Windows\\System32\\inetsrv\\config\\applicationHost.config using NOTEPAD (Notepad++ or any other editor did not work here) as an Administrator.
  2. Move to the <sites> and <application> tag (where your swagger application is hosted) and verify nothing is out of place. My incorrectly configured settings for Swagger did not get reverted here for some reason. Manually cleaning the settings followed by an iisreset fixed the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM