How to redirect root to swagger in Asp.Net Core 2.x?(如何在 Asp.Net Core 2.x 中将 root 重定向到 swagger?)
问题描述
我正在构建与 Swagger 集成的 Asp.Net Core 2.x Web api.要访问 swagger,我必须将/swagger 附加到 url,例如.https://mywebapi.azurewebsites.net/swagger/
I'm building Asp.Net Core 2.x web api integrated with Swagger. To access the swagger, I had to append /swagger to the url, eg. https://mywebapi.azurewebsites.net/swagger/
如何将 https://mywebapi.azurewebsites.net/ 重定向到 https://mywebapi.azurewebsites.net/swagger/ ?
How can I redirect https://mywebapi.azurewebsites.net/ to https://mywebapi.azurewebsites.net/swagger/ ?
推荐答案
从 Nuget 安装 Microsoft.AspNetCore.Rewrite
Install Microsoft.AspNetCore.Rewrite from Nuget
在 Startup.cs 中
In Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
之前
app.UseMvc();
添加
var option = new RewriteOptions();
option.AddRedirect("^$", "swagger");
app.UseRewriter(option);
这篇关于如何在 Asp.Net Core 2.x 中将 root 重定向到 swagger?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Asp.Net Core 2.x 中将 root 重定向到 swagger?


- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04