Correcting the route application in / swagger

What is the correct way to redirect a request from www.mysite.com to www.mysite.com/swagger?

I am setting up an index controller decorated with Route ("") and it works, but it seems Kludge. I suppose there should be a way to specify it in MVC routing in Startup.cs, I just can't figure it out.

// kludge code, how do I do this in app.UseMvc(route => route.MapRoute... [ApiExplorerSettings(IgnoreApi = true)] [Route("")] public class IndexController : Controller { public ActionResult Index() { return Redirect("/swagger"); } } 
+2
source share
2 answers

Try the following redirection rule:

 var option = new RewriteOptions(); option.AddRedirect("^$", "swagger"); app.UseRewriter(option); 
+9
source

I don't have rewriting settings in .Net Core yet, so I might be wrong, but I'm playing with this idea.

Install NuGet Package: Microsoft.AspNetCore.Rewrite

In your configuration method of your startup.cs file.

 app.UseRewriter(new RewriteOptions() .AddRedirect(@"", "swagger/")); 
-one
source

All Articles