Click here to Skip to main content
15,945,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I using swashbuckle v 5.6.0 for api documentation and ui for test in web api2. 
I do not want give ability for the user to post data from swagger ui in production.
How do I disable it?

What I have tried:

               .EnableSwagger(c =>
                   c.Schemes(new[] { "http", "https" });
                   c.SingleApiVersion("v1", ""Demo API");
              .EnableSwaggerUi(c =>
Updated 19-Jun-22 5:45am

Have you looked into there GIT repository and read this issue?
Disabling swagger ui · Issue #301 · domaindrivendev/Swashbuckle · GitHub[^]
Share this answer
If you are using NET framework (any version capable of having swagger)

in you web.config,

1. create a new key called IsSwaggerEnabled and set it to true

    <add key="IsSwaggerEnabled" value="true" />

2. If you installed swagger from nuget package already, then you have the (*\App_Start\SwaggerConfig.cs)

in there find the Register() method and add code as the following

public static void Register()
         var thisAssembly = typeof(SwaggerConfig).Assembly;

         // if key in config does not exist we set it to true
         // you can play to make it always false ***
         bool isSwaggerEnabled = ConfigurationManager.AppSettings["IsSwaggerEnabled"] != null ?
             bool.Parse(ConfigurationManager.AppSettings["IsSwaggerEnabled"]) : true;

         // if swagger is not enabled we don't even bother to config it,
         // therefor will be disabled, and you don't have to worry about it.
         if (!isSwaggerEnabled)

             .EnableSwagger(c =>

 // code below removed for readability
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900