I'm having a problem using the application root notation (e.g. ~/images/fred.gif) when using Context.RewritePath. Scenario: 1. An HttpModule uses Context.RewritePath to rewrite all .aspx requests to ~/siteDefault.aspx 2. siteDefault.aspx loads a template using
LoadControl. The loaded template contains an asp:image with an ImageUrl of ~/images/fred.gif, which should map to /mysite.images/fred.gif. However, if I request http://localhost/mysite/fred/jim/test.aspx, the page loads correctly (i.e. the siteDefault is loading
the page template) but the image is not loaded. If I look at the properties of the missing image in IE, it says that the URL is http://localhost/mysite/fred/jim/images/fred.gif. As another example, if I request http://localhost/mysite/fred/test.aspx, the missing
image's URL is http://localhost/mysite/fred/images/fred.gif. As a further confusion, if my siteDefault.aspx uses Context.RewritePath in the PageInit event, this also sometimes affects the URL of the missing image. If I use Context.RewritePath( "~"), then the
missing URL is http://localhost/mysite/fred/jim/mysite/images/fred.gif. Does anyone have a clue what is going on here?
What I do is I write a tag to my default.aspx that sets the base path for all relative paths on the page to the actual root path for my application. So: In the ASPX file:
... The in the code behind... probably in OnInit or something: BasePath.Attributes.Add("HREF", this.PageBasePath); protected string PageBasePath { get { string basePathString = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,
Request.ApplicationPath); if(!basePathString.EndsWith("/")) basePathString = basePathString + "/"; return basePathString; } }
richtebb
Member
30 Points
6 Posts
RewritePath confuses application root (~)
Sep 23, 2003 06:54 PM|LINK
schilm
Member
60 Points
14 Posts
Re: RewritePath confuses application root (~)
Nov 17, 2003 04:52 AM|LINK
RMD
Member
734 Points
172 Posts
Re: RewritePath confuses application root (~)
Nov 18, 2003 10:33 PM|LINK