asp:Hyperlink NavigateUrl problem

Discussion in 'ASP .Net' started by gerry, Jan 18, 2006.

  1. gerry

    gerry Guest

    I have a page that has an asp:Hyperlink control on it.
    The NavigateUrl is set to "~/Aaa/Bbb.aspx"
    When the link is rendered it is rendered as Aaa/Bbb.aspx which I would think
    is completely incorrect.

    As I understand the use of the this syntax , ~ should be replaced by the
    application path.
    so for an application in the root this value should be /Aaa/Bbb.aspx
    for an application in the /Ccc/Ddd directory this should be
    /Ccc/Ddd/Aaa/Bbb.aspx

    I have a site which directs requests to /Default.aspx via url rewriting
    the problem is for an url http://site/xxx/yyy/xxx.aspx that is rewritten to
    http://site/default.aspx,
    the link ends up with a effective href of http://site/xxx/yyy/Aaa/Bbb.aspx
    whereas I would expect it to be http://site/Aaa/Bbb.aspx regardless of the
    url of the page on which it appears
    - is not the whole point of ~/ to make an url relative to the application
    root rather than relative to the current page ?

    Is this a bug in the Hyperlink control rendering ?
    Or do I completely misunderstand the purpose of the ~/ syntax ?

    Gerry
    gerry, Jan 18, 2006
    #1
    1. Advertising

  2. You probably have http://site/xxx/yyy set as an application, so it will be
    treated as an application path when using "~". If it's possible, you might
    eliminate the above as an application in IIS and then see what happens. (Of
    course, if this subweb is relying on a web.config, then you may not be able
    to do it this way.)
    --
    Christopher A. Reed
    "The oxen are slow, but the earth is patient."

    "gerry" <> wrote in message
    news:%...
    >I have a page that has an asp:Hyperlink control on it.
    > The NavigateUrl is set to "~/Aaa/Bbb.aspx"
    > When the link is rendered it is rendered as Aaa/Bbb.aspx which I would
    > think
    > is completely incorrect.
    >
    > As I understand the use of the this syntax , ~ should be replaced by the
    > application path.
    > so for an application in the root this value should be /Aaa/Bbb.aspx
    > for an application in the /Ccc/Ddd directory this should be
    > /Ccc/Ddd/Aaa/Bbb.aspx
    >
    > I have a site which directs requests to /Default.aspx via url rewriting
    > the problem is for an url http://site/xxx/yyy/xxx.aspx that is rewritten
    > to
    > http://site/default.aspx,
    > the link ends up with a effective href of http://site/xxx/yyy/Aaa/Bbb.aspx
    > whereas I would expect it to be http://site/Aaa/Bbb.aspx regardless of the
    > url of the page on which it appears
    > - is not the whole point of ~/ to make an url relative to the application
    > root rather than relative to the current page ?
    >
    > Is this a bug in the Hyperlink control rendering ?
    > Or do I completely misunderstand the purpose of the ~/ syntax ?
    >
    > Gerry
    >
    >
    >
    Christopher Reed, Jan 21, 2006
    #2
    1. Advertising

  3. gerry

    gerry Guest

    No , in this case the only IIS application is the root , in fact
    http://xxx/yyy doesn't even exist as far as IIS is concerned and there is no
    'subweb'. EVERYTHING is rewritten to /Default.aspx, it is the only thing in
    the website.
    Although I do agree with your assessment of how ~/ should work
    To be safe , .net should always be generating the url from the application
    root ie. /xxx/yyy/Aaa/Bbb.aspx. but it seems as if it is trying to generate
    an url relative to the current page which is fine if it is done right - but
    its not. I ran into this situation myself when trying to generate urls
    relative to the current page using a custom sitemap - I found that you have
    to use Request.RawUrl as the base reference instead of Request.Url. in this
    example RawUrl would be /xxx/yyy/xxx.apsx whereas Url would be /Default.aspx
    so for /xxx/yyy/xxx.aspx the link should be to /Aaa/Bbb.aspx as the 2 urls
    are unrelated
    for /Default.aspx the link should be Aaa/Bbb.aspx as the 2 urls are related
    at the root

    Gerry



    "Christopher Reed" <> wrote in message
    news:eQG2I#...
    > You probably have http://site/xxx/yyy set as an application, so it will be
    > treated as an application path when using "~". If it's possible, you

    might
    > eliminate the above as an application in IIS and then see what happens.

    (Of
    > course, if this subweb is relying on a web.config, then you may not be

    able
    > to do it this way.)
    > --
    > Christopher A. Reed
    > "The oxen are slow, but the earth is patient."
    >
    > "gerry" <> wrote in message
    > news:%...
    > >I have a page that has an asp:Hyperlink control on it.
    > > The NavigateUrl is set to "~/Aaa/Bbb.aspx"
    > > When the link is rendered it is rendered as Aaa/Bbb.aspx which I would
    > > think
    > > is completely incorrect.
    > >
    > > As I understand the use of the this syntax , ~ should be replaced by the
    > > application path.
    > > so for an application in the root this value should be /Aaa/Bbb.aspx
    > > for an application in the /Ccc/Ddd directory this should be
    > > /Ccc/Ddd/Aaa/Bbb.aspx
    > >
    > > I have a site which directs requests to /Default.aspx via url rewriting
    > > the problem is for an url http://site/xxx/yyy/xxx.aspx that is rewritten
    > > to
    > > http://site/default.aspx,
    > > the link ends up with a effective href of

    http://site/xxx/yyy/Aaa/Bbb.aspx
    > > whereas I would expect it to be http://site/Aaa/Bbb.aspx regardless of

    the
    > > url of the page on which it appears
    > > - is not the whole point of ~/ to make an url relative to the

    application
    > > root rather than relative to the current page ?
    > >
    > > Is this a bug in the Hyperlink control rendering ?
    > > Or do I completely misunderstand the purpose of the ~/ syntax ?
    > >
    > > Gerry
    > >
    > >
    > >

    >
    >
    gerry, Jan 22, 2006
    #3
  4. gerry

    Sobot

    Joined:
    Feb 13, 2009
    Messages:
    3
    Location:
    Belgrade
    Solution for problem of absolute URL to NavigateURL

    May be off topic but still relevant...

    For tje problem of absolute url binding to NavigateURL field of asp:HyperLink
    Solution is to use Page_PreRender method to do the binding because it will be overwritten if you do it Page_OnLoad

    can find more here
    asp:HyperLink NavigateUrl Problem Absolute URL

    Link: sobot-software.blogspot.com/2009/02/asphyperlink-navigateurl-problem.html

    Sobot Software DotNetNuke Outsourcing
    Sobot, Feb 13, 2009
    #4
    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. Amir Eshterayeh
    Replies:
    5
    Views:
    9,348
    Sobot
    Feb 13, 2009
  2. Tomek R.
    Replies:
    7
    Views:
    8,193
    Sobot
    Feb 13, 2009
  3. VB Programmer
    Replies:
    3
    Views:
    10,637
    VB Programmer
    Nov 16, 2005
  4. Christoph Schuster

    Problem with Hyperlink.NavigateURL="../../" in WebControls

    Christoph Schuster, Jul 21, 2003, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    287
    Yan-Hong Huang[MSFT]
    Jul 23, 2003
  5. Carl Grainger

    asp:hyperlink - NavigateURL is always relative. I need absolute.

    Carl Grainger, Sep 24, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    380
    Carl Grainger
    Sep 25, 2006
Loading...

Share This Page