I’ve read many articles about relative/absolute paths, but I still can’t grok this problem.
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>
(Note that one link has a ~ and one doesn’t.)
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.
How do I get to the root of my ASP.NET project without it ignoring whatever virtual directories are set up on IIS?
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.