代码之家  ›  专栏  ›  技术社区  ›  Alexander Beletsky

在IIS上运行的应用程序中使用HREF的asp.net mvc

  •  0
  • Alexander Beletsky  · 技术社区  · 14 年前

    有一个表示寻呼机控件的部分视图(非常类似于 this "/Blog/Posts/Page/1" , "/Blog/Posts/Page/2" 等。

    IIS应用程序在虚拟文件夹中运行,因此URL为

    http://localhost/tracky
    

    以及博客区,

    http://localhost/tracky/blog
    

    当我按下寻呼机按钮时,我收到404,因为URL将是

    http://localhost/blog/page/3
    

    http://localhost/tracky/blog/page/3
    

    我的问题是,如何处理这种情况?如何更改代码生成以提供正确的URL?如何使其与根应用程序或虚拟文件夹中的应用程序相同?

    here

    2 回复  |  直到 14 年前
        1
  •  3
  •   spender    14 年前

    您需要通过使用 ActionLink 在您的视图中,或在您的ref中使用UrlHelper,如下所示: <a href="<%=Url.Content("~/blog/page/3")%>" ..>bla</a> . 这将生成根据应用程序根目录调整的url。

        2
  •  0
  •   marcind    14 年前

    您应该使用以下选项:

    UrlHelper.GenerateContentUrl("~/Blog/Posts/Page/1");
    

    这个 ~ 允许相对于应用程序路径解析url,并应在cassini和IIS中生成正确的结果。