简体   繁体   中英

Swashbuckle running with katana-owin based web api doesnt work with IIS but works with IIS Express

I think I have a similar issue as this post- Webactivator doesn't run on IIS 7

Swashbuckle running with katana-owin based web api is able to work with IIS Express.

assume all the urls below have an "http" prefix. I can browse to something like localhost:8085/swagger Which redirects me correctly to localhost:8085/swagger/ui/index

But when published to IIS redirects to localhost/swagger/ui/index instead of localhost/myapp/swagger/ui/index and this results in a 404 . Notice that even though an application name is specified while publishing somehow swashbuckle/swagger doesn't know and only uses the pathbase without the application name.

basically it just picks up the site root URL instead of the application URL that was used to call /swagger

Any solution to this problem?

I got the same issue. Solved this using the following code (c.RootUrl)

config.EnableSwagger(c =>
            {
                c.IncludeXmlComments(GetXmlCommentsPath());

                c.SingleApiVersion("v1", "yourAPI");

                c.RootUrl(req => req.RequestUri.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/").TrimEnd('/'));

            });

Reference : Relative path for UI request URL

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