如何在ASP.NET Core中实施小写路由? [英] How do you enforce lowercase routing in 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 the following line to the ConfigureServices
method of the Startup
class.
services.AddRouting(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中实施小写路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!