【问题标题】:URL routing relative paths with webforms ASP.net 4 and IIS6使用 webforms ASP.net 4 和 IIS6 的 URL 路由相对路径
【发布时间】:2010-06-17 00:24:27
【问题描述】:

我正在尝试在 IIS6 服务器上运行的 asp.net 4.0 站点上配置路由。 我正在使用 MapPageRoute,它会将我带到正确的页面。目前遇到的问题:

1) 无扩展 URL 路由

通过安装此处描述的 QFE 解决了http://blogs.msdn.com/b/tmarq/archive/2010/04/01/asp-net-4-0-enables-routing-of-extensionless-urls-without-impacting-static-requests.aspx

2) js、css、图片等静态内容不显示

使用此处描述的 Chris Cavanagh 的 baseUrl 技术解决了 chriscavanagh.wordpress.com/2008/11/06/aspnet-routing-just-enough-rope/

2) 相对url和回发场景

未解决。由于某种原因,没有正确解释相对路径。例如。 asp:ImageButton runat="server" ImageUrl="~/images/tree.jpg" 使用 src="" 渲染为和 img。我已经能够通过将 ImageUrl 设置为绝对路径来强制它工作,但我不能对所有事情都这样做。它还影响回发方案。按钮点击将我从(例如)localhost/website/articles/the-article_description/ 带到不存在的 localhost/website/the-article-description。

谁能帮我解决这个问题?

【问题讨论】:

    标签: c# asp.net routing


    【解决方案1】:

    您是否将 RouteExistingFiles 属性设置为 true?

    【讨论】:

      【解决方案2】:

      对于像 #3 这样的情况,我一直在那里放置一个函数,该函数返回一个字符串,用作生产站点的前缀 URL。因此,对于您拥有的这一部分:

      mageUrl="~/images/tree.jpg"
      

      将其调整为:

      mageUrl="<%= [YourNameSpace].AppMethod.IsProd() %>/images/tree.jpg"
      

      'AppMethod' 是一些静态类,如果应用程序在生产环境中运行,IsProd() 函数会返回指定生产路径所需的前缀。否则,如果应用程序在 dev 中运行,则前缀“~”。您可以通过读取机器名称来确定应用程序是否在生产环境中运行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-09-11
        • 2012-07-09
        • 2010-10-24
        • 2011-06-05
        • 2012-05-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多