如何在 ASP.NET Core 中强制执行小写路由?

How do you enforce lowercase routing in ASP.NET Core?(如何在 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 中强制执行小写路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)