【问题标题】:Route application root to /swagger将应用程序根路由到 /swagger
【发布时间】:2017-07-03 14:54:27
【问题描述】:

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

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

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

【问题讨论】:

  • 是上面帖子中提到的代码,对你有用吗?因为它在我的情况下不起作用。
  • @VaultBoy14 我需要更多详细信息 1) 使用的是 Asp.Net Core (.NET Core) 还是 Asp.Net (.Net Framework)? 2) 你安装了什么 Swashbuckle (Swagger) NuGet 包?

标签: asp.net-core asp.net-core-mvc swagger swashbuckle


【解决方案1】:

尝试以下重定向规则:

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

app.UseRewriter(option);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-22
    • 2022-12-25
    • 2020-01-19
    • 1970-01-01
    • 2018-07-22
    • 2011-02-28
    • 1970-01-01
    • 2016-06-23
    相关资源
    最近更新 更多