How to get target URL?
I'm writing an application which extracts image files from .css. First I scan the HTML file to extract all .css files:
In HTML I have something like this:<link rel="stylesheet" type="text/css" media="screen" href="TemplatesFBL/Styles/screen.css" />
www.mysite.com/Templates/Styles/screen.css is my first target link.
Inside that file I may have something like this:background-image:url('../Images/CssImg/pageShadowSides.gif');
The question is, how can I combine www.mysite.c开发者_StackOverflow中文版om/Templates/Styles and ../Images/CssImg/pageShadowSides.gif in order to get www.mysite.com/Templates/Images/CssImg/pageShadowSite.gif?
Can I use some built-in function or do I have to write my own?Any help would be greatly appreciated!
You're looking for the Uri
class.
Store a Uri
for the base URL, then create a new Uri
with a relative path:
var baseUri = new Uri("http://www.mysite.com/Templates/Styles/screen.css", UriKind.Absolute);
var fullUri = new Uri(baseUri, "../Images/CssImg/pageShadowSides.gif");
Note that the CSS filename should be included in the URL.
Since it doesn't end in a slash, the Uri parser will realize that it's a filename and behave correctly.
精彩评论