My application paths … <a runat="server" href="~/Home">
…are resolving to “Home” (not “/Home”). After I rewrite URLs, “/Blah/Blah”, all the ”~/” links are relative to the rewrite: /Blah/Home
Is there a way to force a root to “/”?
My application paths … <a runat="server" href="~/Home">
…are resolving to “Home” (not “/Home”). After I rewrite URLs, “/Blah/Blah”, all the ”~/” links are relative to the rewrite: /Blah/Home
Is there a way to force a root to “/”?
Why don't you just write the links relative to the root ('/') instead of '~/', if you're application is not at the root of the domain, then the '~/' links will resolve to the root of the application
If you're sure that, for the links in question you'll always be at a root of "/", then the simplest thing to do is change the <a> so that the href reads "/Home" rather than "~/Home" ... That way asp.net won't parse it and change it to use the App/VDir as its starting point.
If you use standard HTML tags like a, then include the url via
<a href="<%=ResolveUrl("~/Home")%>">...</a>
or use asp.net hyperlinks:
<asp:Hyperlink NavigateUrl="~/Home" runat="server" ID="HomeLink" Text="..." />
That way, all links will point to the right URL, even when the web application will be installed in a subdirectory.
<% %>
is inline coding for asp.net, and <%= %>
outputs the content, in that case the result of ResolveUrl.
Hey,
~/ gets translated in the web controls, as in not Otherwise, you need to use ResolveClientUrl to do that.
For the hyperlink control, it will automatically map correctly for you.