peterc
peterc

Reputation: 7843

asp.net with Owin Swashbuckle basic configuration does not find url when using a virtual directory

I have been following a number of tutorials including this one on adding Swagger via Swashbuckle.

From various posts, I have changed the following in my startup..

      //GlobalConfiguration.Configuration
      // .EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API"))      
      // .EnableSwaggerUi();

      HttpConfiguration httpConfig = new HttpConfiguration();
      SwaggerConfig.Register(httpConfig);      

      WebApiConfig.Register(httpConfig, unityContainer);
      app.UseWebApi(httpConfig);

And in my SwaggerConfig.cs I have...

    //[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]

    namespace Micromine.MyApp
    {
      public class SwaggerConfig
      {
        public static void Register(HttpConfiguration httpConfig)
        {
          httpConfig
               .EnableSwagger(c =>
               {            
                  c.RootUrl(req => SwaggerDocsConfig.DefaultRootUrlResolver(req));         
                  c.SingleApiVersion("v1", "MyCompany.MyApp");             
                  c.IncludeXmlComments(string.Format(@"{0}\bin\myapp.xml", System.AppDomain.CurrentDomain.BaseDirectory));
               })
               .EnableSwaggerUi(c =>
                   {                 
                   });
        }

Problem 1.

When I run my app, I have the following root route...

http://localhost/myapp/

Now if I try to browse to the swagger, ie enter

http://localhost/myapp/swagger

it redirects to http://localhost/swagger/ui/index, ie it does not have myapp in the path.

Problem 2

If I now manually browse to http://localhost/myapp/swagger/ui/index, I now get..

enter image description here

Finally, if I manually enter the following...

enter image description here

my routes show up.

Any ideas how I configure this?

Upvotes: 2

Views: 660

Answers (1)

peterc
peterc

Reputation: 7843

Problem 2 I have fixed following this FAQ.

Problem 1 is still pending, but I have just added my own button to link to the path to get to the Swagger UI, so I am not as worried about this anymore.

Upvotes: 1

Related Questions