I'm working on a Swagger (Web API) project.
When I first run the application it shows the Login page for Swagger UI.
So, a user first has to login to access Swagger UI Page, However, if user directly enters "http://example.com/swagger/ui/index" then he's able to access the Swagger UI page.
afaik the swagger-ui is served by the swashbuckle assembly. The source is not available in my project.
How can I make the user redirect to login page if he's not logged in to Swagger UI page?
Finally, I solved it with
DelegtingHandler
, here's how I did it:Create a file
SwaggerAccessMessageHandler.cs
and add it inApp_Start
folder.Next, Wire up the handler in
SwaggeConfig.cs
just before enabling Swagger as follows: