asp:Hyperlink NavigateUrl problem

G

gerry

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
 
C

Christopher Reed

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.)
 
G

gerry

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
 
Joined
Feb 13, 2009
Messages
3
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top