我正在使用 ASP.NET MVC 6 并尝试使用小写 url 和尾部斜杠。
我使用了以下内容:
RouteTable.Routes.LowercaseUrls = true;
RouteTable.Routes.AppendTrailingSlash = true;
但它给出了编译错误。只是想知道 MVC 6 是否有不同的方式来执行上述操作,还是与我们在 MVC5 中所做的相同?
最佳答案
您现在可以使用 AddRouting 告诉路由引擎使用小写 URL。此代码位于 Startup.cs 文件中:
public void ConfigureServices(IServiceCollection services)
{
// ...ommitted code
services.AddRouting(options =>
{
options.AppendTrailingSlash = true;
options.LowercaseUrls = true;
});
}
关于asp.net-mvc - 小写网址和尾部斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27997814/