Route application root to /swagger

一曲冷凌霜 提交于 2019-12-18 08:55:43

问题


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

I setup an index controller Decorated with Route("") and it works but seems like a Kludge. I assume there should be a way to specify it in the 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");
    }
}

回答1:


Try the following redirect rule:

var option = new RewriteOptions();
option.AddRedirect("^$", "swagger");

app.UseRewriter(option);


来源:https://stackoverflow.com/questions/44888670/route-application-root-to-swagger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!