如何在ASP.NET Core中实施小写路由? [英] How do you enforce lowercase routing in ASP.NET Core?

查看:149
本文介绍了如何在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屋!

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