Question about ~

Discussion in 'ASP .Net' started by Danny Ni, Jun 5, 2008.

  1. Danny Ni

    Danny Ni Guest

    Hello,

    Can someone tell me where the following tag should be pointing to?

    <asp:Image runat="server" ImageUrl="~/images/logo.gif" />

    It renders in IE and FF as
    <img src="images/logo.gif" ....>

    I was expecting something like this
    <img src="/cart/images/logo.gif" ....>

    /cart is my virtual application root.

    TIA
     
    Danny Ni, Jun 5, 2008
    #1
    1. Advertising

  2. You are correct. "~" is a placeholder for the application path (application
    root folder).

    To render urls most web controls use paths relative to the directory
    containing the current page.
    When browser resolves such relative url it starts from the current page
    location.

    In your case if page is located in /cart folder (application root) then
    ~/images/logo.gif is resolved to images/logo.gif

    Regards,

    Alexander Myachin


    "Danny Ni" <> wrote in message
    news:...
    > Hello,
    >
    > Can someone tell me where the following tag should be pointing to?
    >
    > <asp:Image runat="server" ImageUrl="~/images/logo.gif" />
    >
    > It renders in IE and FF as
    > <img src="images/logo.gif" ....>
    >
    > I was expecting something like this
    > <img src="/cart/images/logo.gif" ....>
    >
    > /cart is my virtual application root.
    >
    > TIA
    >
     
    Alexander Myachin, Jun 5, 2008
    #2
    1. Advertising

  3. Hello Danny,

    Read about asp.net paths there http://msdn.microsoft.com/en-us/library/ms178116(VS.80).aspx

    ---
    WBR,
    Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

    "The greatest danger for most of us is not that our aim is too high and we
    miss it, but that it is too low and we reach it" (c) Michelangelo


    DN> Hello,
    DN>
    DN> Can someone tell me where the following tag should be pointing to?
    DN>
    DN> <asp:Image runat="server" ImageUrl="~/images/logo.gif" />
    DN>
    DN> It renders in IE and FF as
    DN> <img src="images/logo.gif" ....>
    DN> I was expecting something like this
    DN> <img src="/cart/images/logo.gif" ....>
    DN> /cart is my virtual application root.
    DN>
    DN> TIA
    DN>
     
    Michael Nemtsev [MVP], Jun 5, 2008
    #3
  4. Hi, Danny.

    ~ always refers to the application root.

    If your application root is /cart, then the relative path
    from /cart to ~/images/logo.gif is images/logo.gif.

    re:
    !> It renders in IE and FF as
    !> <img src="images/logo.gif" ....>

    Yes, that is the correct relative path.

    re:
    !> I was expecting something like this
    !> <img src="/cart/images/logo.gif" ....>

    That would be a path which includes the root directory.
    Relative paths don't need to include the root directory.

    If your root directory is /cart, then the relative path
    /cart/images/logo.gif would point to /cart/cart/images/logo.gif





    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espaƱol : http://asp.net.do/foros/
    ======================================
    "Danny Ni" <> wrote in message news:...
    > Hello,
    >
    > Can someone tell me where the following tag should be pointing to?
    >
    > <asp:Image runat="server" ImageUrl="~/images/logo.gif" />
    >
    > It renders in IE and FF as
    > <img src="images/logo.gif" ....>
    >
    > I was expecting something like this
    > <img src="/cart/images/logo.gif" ....>
    >
    > /cart is my virtual application root.
    >
    > TIA
    >
    >
     
    Juan T. Llibre, Jun 5, 2008
    #4
  5. Danny Ni

    Stan Guest

    On 5 Jun, 02:31, "Danny Ni" <> wrote:
    > Hello,
    >
    > Can someone tell me where the following tag should be pointing to?
    >
    > <asp:Image runat="server" ImageUrl="~/images/logo.gif" />
    >
    > It renders in IE and FF as
    > <img src="images/logo.gif" ....>
    >
    > I was expecting something like this
    > <img src="/cart/images/logo.gif" ....>
    >
    > /cart is my virtual application root.
    >
    > TIA


    Hi Danny

    Unless you state the path of the page containing the url no one can
    predict specifically what the result will be.

    For example if the site relative address of the page was /cart/
    Apage.aspx then the result will be as already shown. If it was say /
    cart/Afolder/Apage.aspx then the result will be ../images/logo.gif.

    I must also stress that it is the server that does the translation of
    application relative addresses (those using the ~ character) not the
    browser, so it wont make any difference which browser you use. The ~
    symbol would not be recognised on the client (besides the browser has
    no way of knowing where in the full url the application root is). The
    server replaces ~ with a normal W3C compliant relative address when
    rendering the page (as in my exampe).

    On receipt of a relative address the browser reconstructs the full
    path based on the url of the requested page. So, for example, if
    http://yourdomain.com/cart/Afolder/Apage.aspx returned an image with
    an src="../images/logo.gif" it would send a request for the image file
    to http://yourdomain.com/cart/images/logo.gif

    HTH
     
    Stan, Jun 5, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    614
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    682
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    964
    Scott Allen
    Oct 6, 2005
  4. Philip Meyer
    Replies:
    0
    Views:
    438
    Philip Meyer
    Nov 30, 2003
  5. Bit Byte
    Replies:
    1
    Views:
    870
    Teemu Keiski
    Jan 28, 2007
Loading...

Share This Page