Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2003, 04:38 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default ResolveURL("~/...") -> ???

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
__________________
-Peter
compiledthoughts.com
twitter/peterlanoie





Similar Threads
Thread Thread Starter Forum Replies Last Post
ResolveUrl in ASP.NET Manoj Bisht ASP.NET 2.0 Professional 2 March 10th, 2009 12:59 AM
Chpt 7 >> Pg 245 >>Try It Out #4-5 harrison4411 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 March 2nd, 2006 06:26 PM
Achitecture ? SQL -> XML -> ASP -> PDF or HTML Frm jstrong Classic ASP XML 0 July 9th, 2005 01:18 PM
Chapter 4> ERROR using "=>>>" guiro BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 5 January 13th, 2005 06:38 PM
VB.Net -> Filename -> DTS Package -> tempdB daniel Pro VB.NET 2002/2003 1 October 7th, 2004 01:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.