How do you enforce lowercase routing in ASP.NET Core?(如何在 ASP.NET Core 中强制执行小写路由?)
问题描述
在 ASP.NET 4 中,这就像应用程序的 RegisterRoutes
处理程序中的 routes.LowercaseUrls = true;
一样简单.
In ASP.NET 4 this was as easy as routes.LowercaseUrls = true;
in the RegisterRoutes
handler for the app.
我在 ASP.NET Core 中找不到实现此目的的等效项.我想它会在这里:
I cannot find an equivalent in ASP.NET Core for achieving this. I'd think it would be here:
app.UseMvc(configureRoutes =>
{
configureRoutes.MapRoute("Default", "{controller=App}/{action=Index}/{id?}");
});
但 configureRoutes
中似乎没有任何内容允许它...除非在某个地方有我在文档中找不到的扩展方法?
But nothing in configureRoutes
looks to allow it... unless there's an extension method somewhere that I can't find in the docs perhaps?
推荐答案
对于 ASP.NET Core:
For ASP.NET Core:
在 Startup
类的 ConfigureServices
方法中添加以下行之一:
Add one of the following lines to the ConfigureServices
method of the Startup
class:
services.AddRouting(options => options.LowercaseUrls = true);
或
services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
感谢 Skorunka 作为评论的回答.我认为值得推广为实际答案.
Thanks to Skorunka for the answer as a comment. I thought it was worth promoting to an actual answer.
这篇关于如何在 ASP.NET Core 中强制执行小写路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 ASP.NET Core 中强制执行小写路由?


- 带问号的 nvarchar 列结果 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 使用 rss + c# 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01