Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 03, 2009 02:43 PM by Ilya22
Sep 03, 2009 02:09 PM|LINK
I have a class that combines several html files into one document. These files have relative links to images (e.g. <img src="image.jpg">).
I'm converting my combined document to PDF. I need to translate all relative image links to absolute URLs to make images show up in the generated PDF. What I’m trying to do is to get the base URL of my application within class (like http://mydomain.com/app)
and then modify image SRC attribute accordingly. However, I can’t find a way to get the base URL from class.
I can do HttpContext.Current.Server.MapPath("~"), but it gives me back a file path instead of URL: c:\inetpub\wwwroot\app
Could you please tell me if there is a way to do something similar to ResolveUrl("~/")inside class to get the URL, not physical path (ResolveUrl doesn’t work inside class)?
If it not possible, can anyone give me any advise on possible alternative solutions?
Sep 03, 2009 02:17 PM|LINK
(HttpContext.Current.Request.ApplicationPath.Equals("/")) ? string.Empty : HttpContext.Current.Request.ApplicationPath
Hope this helps,
Sep 03, 2009 02:19 PM|LINK
You can also set a breakpoint on that line, highlight Request.Url, then right click, then Quickwatch and expand the node to see all the properties in there. One of them should match exactly what you need, or you'll need to concatenate it.
Sep 03, 2009 02:39 PM|LINK
Sep 03, 2009 02:43 PM|LINK
When I try Request.Url.Authority; I get an error message "The name 'Request' dos not exist in a current context". Well, in any way Shane gave me solution for this problem -- thanks.