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

查看:207
本文介绍了将应用程序根目录路由到/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");
    }
}

推荐答案

尝试以下重定向规则:

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

app.UseRewriter(option);

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

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