Help: root path reference

Discussion in 'ASP .Net' started by hb, Jan 28, 2005.

  1. hb

    hb Guest

    Hi,

    Recently I read some articles about the root path reference in ASP.Net
    application.
    One recommended way is to use "~" at the beginning of the path with server
    control.
    for example:
    <img runat="server" src="~/images/logo1.jpg">

    Those articles also say that such method works with virtual directory as
    well.

    My question is: Is there any performance setback to use server side HTML
    tag (like <img runat="server">)or even ASP.Net server control (like
    <asp:image>)
    instead of regular HTML tag (like <img>) just for root reference purpose?

    Thank you

    Hongbo
     
    hb, Jan 28, 2005
    #1
    1. Advertising

  2. hb

    Karl Seguin Guest

    Re: root path reference

    Hongbo:
    Yes, there is a performance setback, but it's very small and probably worth
    paying it (we are talking microseconds most likely).

    If this isn't acceptable, you can have a global class with a property such
    as:

    public sealed class Globals{
    static public string ApplicationPath {
    get {
    string applicationPath = HttpContext.Current.Request.ApplicationPath;
    if (applicationPath == "/") {
    return string.Empty;
    }
    return applicationPath;
    }
    }
    }
    }

    and then use src="<%=Globals.ApplicationPath%>images/logo1.jpg" but I my
    personal opinion is that ~ is much nicer and cleaner with a very low cost.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "hb" <> wrote in message
    news:ONgp5%...
    > Hi,
    >
    > Recently I read some articles about the root path reference in ASP.Net
    > application.
    > One recommended way is to use "~" at the beginning of the path with server
    > control.
    > for example:
    > <img runat="server" src="~/images/logo1.jpg">
    >
    > Those articles also say that such method works with virtual directory as
    > well.
    >
    > My question is: Is there any performance setback to use server side HTML
    > tag (like <img runat="server">)or even ASP.Net server control (like
    > <asp:image>)
    > instead of regular HTML tag (like <img>) just for root reference purpose?
    >
    > Thank you
    >
    > Hongbo
    >
    >
    >
     
    Karl Seguin, Jan 28, 2005
    #2
    1. Advertising

  3. hb

    hb Guest

    Re: root path reference

    Karl,

    Thank you every much.
    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:...
    > Hongbo:
    > Yes, there is a performance setback, but it's very small and probably

    worth
    > paying it (we are talking microseconds most likely).
    >
    > If this isn't acceptable, you can have a global class with a property such
    > as:
    >
    > public sealed class Globals{
    > static public string ApplicationPath {
    > get {
    > string applicationPath =

    HttpContext.Current.Request.ApplicationPath;
    > if (applicationPath == "/") {
    > return string.Empty;
    > }
    > return applicationPath;
    > }
    > }
    > }
    > }
    >
    > and then use src="<%=Globals.ApplicationPath%>images/logo1.jpg" but I my
    > personal opinion is that ~ is much nicer and cleaner with a very low cost.
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "hb" <> wrote in message
    > news:ONgp5%...
    > > Hi,
    > >
    > > Recently I read some articles about the root path reference in ASP.Net
    > > application.
    > > One recommended way is to use "~" at the beginning of the path with

    server
    > > control.
    > > for example:
    > > <img runat="server" src="~/images/logo1.jpg">
    > >
    > > Those articles also say that such method works with virtual directory as
    > > well.
    > >
    > > My question is: Is there any performance setback to use server side HTML
    > > tag (like <img runat="server">)or even ASP.Net server control (like
    > > <asp:image>)
    > > instead of regular HTML tag (like <img>) just for root reference

    purpose?
    > >
    > > Thank you
    > >
    > > Hongbo
    > >
    > >
    > >

    >
    >
     
    hb, Jan 28, 2005
    #3
    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. Replies:
    0
    Views:
    1,241
  2. yburtin
    Replies:
    2
    Views:
    636
    yburtin
    Oct 26, 2004
  3. Rick Osborn
    Replies:
    10
    Views:
    3,959
    Jon A. Cruz
    Feb 8, 2004
  4. hector
    Replies:
    5
    Views:
    413
    CBFalconer
    Dec 5, 2006
  5. John Kotuby

    Reference to Virtual Root path not working

    John Kotuby, May 23, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    642
Loading...

Share This Page