开发者

What does ~ in the beginning of an URL in asp.net exactly do?

I am editing a certain website which before used the port 80 (default) that was not required at the url (because it's default..)

But the port had (for technical reasons) to be changed, and now it has to be informed.

I can access the main page through ip:port\page like this:

1.2.3.4:81\page.aspx

Every link in the website is composed like this:

<asp:HyperLink runat="server" Text="random" NavigateUrl="~/fdr/whatever.aspx" />

And whenever I click on a link, the page doesn开发者_Python百科't load, but the URL is composed on the URL bar of the browser, then I simply add ":80" after the IP in the URL and it works.

Due to the existance of querystrings (in other words, for already having access to the URL) I before thought that '~' in the beginning of a URL in a link was saying "keep in the same website, just change to this webpage in this folder", but if the port vanishes, I assume now that the address is requested (probably to IIS) for the location of the current website.

I want to know then (instead of having to add the port to each link in my website) how do I set up whoever is requested by the ~ in the link to add the port somehow. How do I do that?

--[EDIT]--

Check this other question of mine for more info:

URL losing port number in every page load


It points to the current root directory of the asp.net app (which may live in a subdirectory of the website). It allows links to be coded independent from whether the app lives in the root folder or not.

The Port / domain is never part of the game. Ports are assumed to be 80 -by your browser.

That said, what please is the technical reason to move an app off port 80? I know of not a single valid reason, sorry ;)


The ~ sign is known as the application root operator. You can read more about it here (MSDN) and to quote:

ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root.

The following example shows the ~ operator used to specify a root-relative path for an image when using the Image server control In this example, the image file is read from the Images folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located.

It's essentially a shortcut for the property System.Web.HttpRuntime.AppDomainAppVirtualPath.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜