简体   繁体   中英

relative to root directory in ASP.NET

I know "/" refer to the root, so we can have something like

<link href="/Styles/Order.css" rel="stylesheet" />

which refer a file path that's relative to the root directory.

But if the element is a server control, I saw a piece of code like this:

<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/banner.jpg" />

so why we can't use ImageUrl="/Images/banner.jpg", why we have too add "~" before "/"?

You don't have to. Did you bother trying it? The reason it's there is that ~/ is special syntax in ASP.NET for pointing to the root of the application, which in most cases will be the same as the normal root ( / ). However, if your site is hosted in a different directory, let's say http://example.com/mysite then ~/ will point to http://example.com/mysite while / will point to http://example.com

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