Chris Knight
Chris Knight

Reputation: 1476

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();
        }
    }
}

Upvotes: 10

Views: 27247

Answers (9)

Gesuele Russello
Gesuele Russello

Reputation: 185

I started my project and I added the NuGet for Swagger just "SwashBuckle" and swagger was working fine it I put my ...Localhost:1234/swagger it would redirect to /swagger/ui/index page. Than I updated the NuGet packages and I added two classes in my code to create some filter for swagger. Than the error started.. When I put swagger on the url i get the 403 error. I tried all the above and nothing worked, but what I realize is that I did something stupid where I put the two modules in a folder call "swagger" at the root of my project. As soon as I rename the folder to "swaggerExtraFilters" the redirect start to work again as normal. I hope my stupid mistake help with your problem...

Upvotes: 0

fullStackChris
fullStackChris

Reputation: 1502

Coming at you in 2021 / 2022, this is a fun one.

If you are on macOS, Apple's new airplay feature is on by default and listens to ports 5000 and 7000... sigh. Bad clash with the default swagger port (also 5000)!

Just go to System Preferences > Sharing > Uncheck "AirPlay Receiver" at the bottom of the list. Then restart your .NET application, and the Swagger UI should finally be showing up again in your browser!

Hoping this helps anyone who runs into this weird issue!

Upvotes: 3

hubert17
hubert17

Reputation: 304

I have this issue and it's route and static directory conflict. For Web Api 2, make sure you don't have a static folder named 'swagger'. For .NET Core, remove folder named 'swagger' in wwwroot.

Upvotes: 1

Gajendra
Gajendra

Reputation: 1291

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.

Upvotes: 13

albtvenki
albtvenki

Reputation: 180

I was having the same issue. After trying few things it still didn't work. Then, I tried changing the Web API application port number as suggested at the link below and it worked. I'm not sure what caused the issue.

https://github.com/domaindrivendev/Swashbuckle/issues/618

Upvotes: 2

Gomes
Gomes

Reputation: 3330

This solved me in .net core web api

install this nuget package Microsoft.AspNetCore.StaticFiles

Upvotes: 0

german1311
german1311

Reputation: 93

By some reason changing the order of calls in Application_Start, will fix the problem, this is what I have:

AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
**GlobalConfiguration.Configure(SwaggerConfig.Configure);**
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);  
XmlConfigurator.Configure();

Upvotes: 0

Daniel Sklenitzka
Daniel Sklenitzka

Reputation: 2246

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.

Upvotes: 18

Martin
Martin

Reputation: 664

Try with this URL, http://mybaseurl/swagger/ui/index instead of http://mybaseurl/swagger/

Upvotes: 0

Related Questions