简体   繁体   中英

Relative link to root of IIS Application

In IIS 8.5 I have a Default Web Site under which I have multiple Applications. Several of these Applications are actually the same website code deployed for different user groups, each pointing to different databases with different configurations and so on.

Is it possible to create a hyperlink in my website which links to the root of the APPLICATION rather than the WEBSITE? If I use something like <a href="/" >Go Home</a> then clicking on the link doesn't navigate to http://myserver/myapplication , it links to http://myserver .

Obviously I could hard code the link, but that would mean having to edit the code for each deployment of the website. I could probably get around that by storing the root URL in a configuration file, and maybe that's the only way to achieve what I'm looking for, but it seems overly complicated!

Additionally, when I'm running the website in debug on my development machine, the URL is something like http://localhost:12345 (ie there is no application name), so even if I did store the root URL somewhere, it wouldn't work in development without additional work.

I know I could use a relative path like <a href="../">Go Home</a> to navigate upwards a certain number of levels, but I'm trying to use this link on a custom error page, so ideally I'd like it to work even if the user has somehow navigated to something like http://myserver/myapplication/foo/bar/foo/bar/foo/bar , in which case my link needs to navigate up six levels. The point is, I don't know how many levels down the page containing the link might be.

I naively assumed there'd be a shortcut in the manner of <a href="/"... to get to the application root, but it seems I was wrong!

Prior to version 4 of , you would use the following code:

<a href="Url.Content("~/") ">Root</a>

With version 4 and higher, automatically looks for tilde's so you can just:

<a href="~/">Root</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM