Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger gives me HTTP Error 403.14 - Forbidden

I am trying to use Swagger with Web API. I am just using the "Azure API App" template from the ASP.NET 4.6 templates installed with Visual Studio, which includes the Swashbuckle.Core and the SwaggerConfig.cs. The API works fine (I am able to call it successfully), but if I try to go to "http://mybaseurl/swagger/", I get this error:

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

It seems like Swagger is not getting loaded or something. Anyone else get this before? I can't seem to get around this. Thank you, and please let me know if I can provide more details.

Here is what my SwaggerConfig.cs looks like:

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

namespace With.Api
{
    public class SwaggerConfig
    {
        public static void Register(HttpConfiguration config)
        {
            var thisAssembly = typeof(SwaggerConfig).Assembly;

            config.EnableSwagger(c =>
            {
                c.SingleApiVersion("v1", "With.Api");
            })
            .EnableSwaggerUi();
        }
    }
}
like image 889
Chris Knight Avatar asked Jan 23 '16 23:01

Chris Knight


2 Answers

I just had the same problem. It worked fine when I deployed my app to Azure, but when I started it locally, Swagger just wouldn't show up just as described above. Reverting to a previous version I knew was working before also didn't help, so it seemed to have something to do with IIS express. I'm not entirely sure what was causing the issue (I had changed some SSL related settings), but when I deleted the .vs folder (which contains the applicationhost.config file) and restarted Visual Studio, it started working again.

like image 116
Daniel Sklenitzka Avatar answered Oct 22 '22 10:10

Daniel Sklenitzka


It's an old question, but it would be helpful for someone facing the same problem

If your project has a folder named swagger at root level, it conflicts and you will be not able to access swagger by hostname/swagger.

The solution is to just rename the Swagger folder to another name, then it works.

like image 12
Gajendra Avatar answered Oct 22 '22 10:10

Gajendra