gpt4 book ai didi

c# - ASP.NET MVC 路由不适用于 .html 扩展

转载 作者:太空狗 更新时间:2023-10-29 23:13:40 25 4
gpt4 key购买 nike

我使用 ASP.NET MVC 开发 Web 应用程序。我的路线有问题。

我需要这样的路线。 http://localhost/content-name/23.html

我已经为此定义了一条路线,如下所示

//i need this route but it's not work
routes.MapRoute(
"GetContent",
"{sefLink}/{contentId}.html",
new { controller = "Content", action = "GetContent" },
new[] { "CanEcomm.Controllers" });

但是路线不行。 IIS 显示 404 页面。当我删除 .html 扩展名时,路由有效。

//this route is working. i just remove ".html" extension
routes.MapRoute(
"GetContent",
"{sefLink}/{contentId}",
new { controller = "Content", action = "GetContent" },
new[] { "CanEcomm.Controllers" });

我该如何解决这个问题?谢谢

最佳答案

我已将 HtmlFileHandler 添加到我的 web.config 中。 .html 路由现在可以工作了。

<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

关于c# - ASP.NET MVC 路由不适用于 .html 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33682356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com