如何在 .NET Core 5 MVC 中使用 RouteOptions?(强制使用小写 URL 等)

Nic*_*ckG 3 asp.net-core-mvc asp.net-core-5.0

我想在我的应用程序中使用小写 URL,并且我可以看到此处记录了一个 RouteOptions 对象:

https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.routing.routeoptions?view=aspnetcore-5.0

但实际如何使用RouteOptions 呢?

我认为它会类似于下面的内容,但它只是生成一个编译器警告,指出 app.UseRouting() 不带任何参数:

app.UseRouting(options => {
    options.<no intellisense>
});
Run Code Online (Sandbox Code Playgroud)

那么有人可以告诉我在哪里可以指定 RouteOptions 吗?

Dav*_*idG 5

您需要在您的ConfigureServices方法中进行配置,例如:

services.Configure<RouteOptions>(options =>
{
    options.LowercaseUrls = true;
});
Run Code Online (Sandbox Code Playgroud)