Question about ~

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Danny Ni

    Question about ~

    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

    #2
    Re: Question about ~


    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" <dndn@yahoo.com wrote in message
    news:OgWUrvqxIH A.524@TK2MSFTNG P05.phx.gbl...
    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
    >

    Comment

    • Michael Nemtsev [MVP]

      #3
      Re: Question about ~

      Hello Danny,

      Read about asp.net paths there http://msdn.microsoft.com/en-us/libr...16(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


      DNHello,
      DN>
      DNCan someone tell me where the following tag should be pointing to?
      DN>
      DN<asp:Image runat="server" ImageUrl="~/images/logo.gif" />
      DN>
      DNIt renders in IE and FF as
      DN<img src="images/logo.gif" ....>
      DNI was expecting something like this
      DN<img src="/cart/images/logo.gif" ....>
      DN/cart is my virtual application root.
      DN>
      DNTIA
      DN>


      Comment

      • Juan T. Llibre

        #4
        Re: Question about ~

        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" <dndn@yahoo.com wrote in message news:OgWUrvqxIH A.524@TK2MSFTNG P05.phx.gbl...
        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
        >
        >

        Comment

        • Stan

          #5
          Re: Question about ~

          On 5 Jun, 02:31, "Danny Ni" <d...@yahoo.com 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

          Comment

          Working...