2

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 "/"?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments