将应用程序根路由到/swagger [英] Route application root to /swagger

查看:15
本文介绍了将应用程序根路由到/swagger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将请求从 www.mysite.com 重定向到 www.mysite.com/swagger 的正确方法是什么?

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

我设置了一个用 Route("") 装饰的索引控制器,它可以工作,但看起来像一个 Kludge.我认为应该有一种方法可以在 Startup.cs 的 MVC 路由中指定它,我就是想不通.

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");
    }
}

推荐答案

试试下面的重定向规则:

Try the following redirect rule:

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

app.UseRewriter(option);

这篇关于将应用程序根路由到/swagger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆