BaseHref

I discovered this morning a conflict between the HTML tag BaseHref and ~.

I like to use ~ in my code, making my life easier. But for the standards links (not server side), I tried to implement BaseHref in my ASPX pages.

This created a lot of bad Urls everywhere I used ~.  It seems that BaseHref override the ~ effect.

So if I have a control ith a link to a root page in a subfolder name mycontrols, this is what's happens:

Without BaseHref

MyWebroot/MyPage.aspx

With BaseHref

MyWebroot/mycontrols/MyPage.aspx

Obviously it's wrong.

Not sure exactly where the problem is coming from.

Any idea ?

 

1 Comment

  • For standard links I use something like



    href='<%= Page.ResolveUrl("~/SomeFolder/SomePage.aspx") %>'



    I think for your With BaseHref it is going from the controls perspective (probably a user control), calling <%= ResolveUrl() %> from a userControl will give the resolvedUrl from the controls perspective, using Page.ResolveUrl will give the whole sites perspective and the correct answer. I think its a similar problem here.

Comments have been disabled for this content.