How do you resolve a url like "../../images/test.png" to "http://yoursite.com/images/test.png" in a static asp.net web method?
Asked
Active
Viewed 5,090 times
3 Answers
8
Here is a blog entry from Rick Strahl that might help: http://www.west-wind.com/weblog/posts/154812.aspx

Daniel Dyson
- 13,192
- 6
- 42
- 73
-
jip, that is a really good article, but if I understand the code correctly it would not work for situations where your have ../../../ etc in the url. but I could be wrong – Daniel Brink Jun 23 '10 at 11:54
-
Is the images folder in the root directory? If so, replace ../../ with ~/ That is what the resolver is supposed to do, change ~/ to the appropriate path, depending on the nesting level of the page. – Daniel Dyson Jun 23 '10 at 12:00
-
i cannot replace ../../ with ~/ as any number of ../ relative paths to various pages and files can be passed to my static webmethod. i therefore need a way to convert a relative path such as ../1/2/3/4/page.aspx to http ://abc.com/a/b/s/1/2/3/4/page.aspx – Daniel Brink Jun 23 '10 at 12:07
-
Ok, I think you need to provide more examples of what you need to do in your question – Daniel Dyson Jun 23 '10 at 12:21
0
I was able to use the current Context and application paths together:
Uri uri = new Uri(HttpContext.Current.Request.Url,
System.IO.Path.Combine(HttpContext.Current.Request.ApplicationPath,
"Reports/CareerDev.aspx"));
return uri.AbsoluteUri;

Derek Wade
- 697
- 8
- 11