Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect root to swagger in Asp.Net Core 2.x?

I'm building Asp.Net Core 2.x web api integrated with Swagger. To access the swagger, I had to append /swagger to the url, eg. https://mywebapi.azurewebsites.net/swagger/

How can I redirect https://mywebapi.azurewebsites.net/ to https://mywebapi.azurewebsites.net/swagger/ ?

like image 632
Syaiful Nizam Yahya Avatar asked Mar 15 '18 02:03

Syaiful Nizam Yahya


1 Answers

Install Microsoft.AspNetCore.Rewrite from Nuget

In Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env) 

before

app.UseMvc(); 

add

var option = new RewriteOptions(); option.AddRedirect("^$", "swagger"); app.UseRewriter(option); 
like image 68
Syaiful Nizam Yahya Avatar answered Sep 29 '22 23:09

Syaiful Nizam Yahya