Relative and absolute paths on ASP.NET/IIS

I have read many articles on relative / absolute paths, but I still can not understand this problem.

The following code is presented on my ASP.NET page Master:

<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>

(Note that one link has ~, and the other does not.)

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

How do I get to the root of my ASP.NET project without ignoring which virtual directories are configured on IIS?

+5
source share
4 answers

runat="server" . ~ root HTML. (Html ​​ Web) .

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

Page.ResovleUrl , , :

<a href='<%= Page.ResolveUrl("~/Reports/Two.aspx")%>'>Two</a>
+12

, ,

http://yourhost/app/default.aspx

reports/one.aspx http://yourhost/app/reports/one.aspx. / . .

, , /, , http://yourhost/reports/one.aspx.

~ - . .NET - , ASP.NET, . , http://yourhost/app, http://yourhost/app/views/default.aspx, .NET ~/reports/one.aspx', you would be given http://yourhost/app/reports/one.aspx `.

~ HTML, IIS URL-, , , .

. Unix ~ , .

+5

Please read. There is something about the "Path" for ASP.NET beginners . It will give a complete picture of the "Path" in an ASP.NET application.

+1
source

All Articles