在ASP.NET/IIS相对和绝对路径 [英] Relative and absolute paths on ASP.NET/IIS

查看:360
本文介绍了在ASP.NET/IIS相对和绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过有关相对/绝对路径很多文章,但我仍然无法神交这个问题。

I've read many articles about relative/absolute paths, but I still can't grok this problem.

以下code是从我的ASP.NET 页:

The following code is from my ASP.NET Master page:

<li><a>Reports</a>
    <ul>
        <li>
            <a href="/Reports/One.aspx">One</a>
        </li>
        <li>
            <a href="~/Reports/Two.aspx">Two</a>
        </li>
    </ul>
</li>

(注意,一个环节有一个和一个没有。)

在运行网站,第一个链接指向 HTTP://server/Reports/One.aspx ,以及第二个链接指向HTTP://server/company/project/Reports/~/Reports/Two.aspx

When running the site, the first link points to http://server/Reports/One.aspx, and the second link points to http://server/company/project/Reports/~/Reports/Two.aspx.

我如何得到我的ASP.NET项目的根目录没有它忽略任何虚拟目录上设置IIS?

How do I get to the root of my ASP.NET project without it ignoring whatever virtual directories are set up on IIS?

推荐答案

添加 =服务器属性锚标记。你不能用HTML标签使用〜根运营商。只有服务器控件(HTML或Web),可以使用它。

Add runat="server" attribute to the anchor tag. You can't use the ~ root operator with HTML tags. Only the server controls (Html or Web) can use it.

<a runat="server" href="~/Reports/Two.aspx">Two</a>

这篇关于在ASP.NET/IIS相对和绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆