在 Startup.cs 中设置路由选项 IgnoreCase 为 true。
在施加 Blazor Server 路由规则时,路由路径的大小写敏感问题可能会对应用程序的功能造成影响。解决方案是在 Startup.cs 中设置路由选项 IgnoreCase 为 true。
如下所示:
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapFallbackToFile("/offline.html", "text/html");
});
app.UseBlazorFrameworkFiles();
通过添加 options 参数并在其中设置 IgnoreCase 为 true,即可解决大小写敏感问题。
app.UseRouting(options => options.LowercaseUrls = true);
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapFallbackToFile("/offline.html", "text/html");
});
app.UseBlazorFrameworkFiles();
这里的 LowercaseUrls 是用于完全禁用路径大小写敏感的属性。如果您所需的路由不仅仅是敏感大小写问题,还应该进行更全面的路由调整。