简体   繁体   中英

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

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.

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.

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

尝试使用此URL,而不是http://mybaseurl/swagger/ ,即http://mybaseurl/swagger/ui/index

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

This solved me in .net core web api

install this nuget package Microsoft.AspNetCore.StaticFiles

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.

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