I have this scenario:
In web application "MyWebApp" I have a HyperLink web control in a usercontrol that's used on various pages. These pages live in multiple levels (in subdirectories) in the application.
Code in usercontrol:
HyperLink.ImageURL = "~/images/someimage.png"
HyperLink.NavigateURL = "~/index.aspx"
These values are implicitly pumped thru Control.ResolveURL().
Using .Net Framework 1.0 the URLs are changed into absolute references (i.e. relative to the server root: "http://localhost/<starthere>") -
Call "http://localhost/MyWebApp/index.asp"
Get <a href="/MyWebApp/index.aspx"><img src="/MyWebApp/images/someimage.png"></a>
Call "http://localhost/MyWebApp/subdirectory/anotherpage.asp"
Get <a href="/MyWebApp/index.aspx"><img src="/MyWebApp/images/someimage.png"></a>
This is what I want. "~" is replaced with the application virtual directory so that the absolute reference is good.
Now with Framework 1.1 the URLs are changed to relative references (i.e. relative to the page's parent directory: "http://localhost/MyWebApp/<subdirectories>/<starthere>") and back references ("../") are used -
Call "http://localhost/MyWebApp/index.asp"
Get <a href="index.aspx"><img src="images/someimage.png"></a>
Call "http://localhost/MyWebApp/subdirectory/anotherpage.asp"
Get <a href="../index.aspx"><img src="../images/someimage.png"></a>
This doesn't seem to be TOO much of a problem when the pages work correctly. However, I have an error page "error/err404.aspx". When I call "http://localhost/MyWebApp/breakit.aspx" to force a 404 error the browser is
redirected to "http://localhost/MyWebApp/error/err404.aspx?aspxerrorpath=/MyWebApp/breakit.aspx". This works fine.
If I try "http://localhost/MyWebApp/breakit", it seems that execution is
transferred to the error page, and the browser is in the context of "http://localhost/MyWebApp" so the "../" translate to the wrong place. So now the logical evaluation ends up looking like this:
../images/someimage.png
http://localhost/MyWebApp/../images/someimage.png
http://localhost/images/someimage.png (BREAK!)
It seems that they have changed the behavior of the "~" replacement. Of course, I can't seem to find any documentation on this little feature, I came across it on a forum and was very happy to find it. (MS obviously saw the helpfulness of the *nix use of ~ to mean "home directory".)
Anyone have any idea? Is there some obscure web.config setting to change the behavior of Control.ResolveURL()?
Peter