i swear i used to be able to pass relative URLs into the WebRequest
method, like so:
string relativePath = "/foo/bar.html";
WebRequest request = HttpWebRequest.Create(relativePath);
WebResponse response = request.GetResponse();
...now that generates an exception:
"Invalid URI: The format of the URI could not be determined."
so then i figured out how to create a full URL path ("http://...")
like so:
string relativePath = "/foo/bar.html";
//get the main url
string authority =
System.Web.HttpContext.Current.Request.Url.GetLeftPart
(UriPartial.Authority);
//add the supplied relative path
Uri uri = new Uri(authority + relativePath);
WebRequest request = HttpWebRequest.Create(uri.AbsoluteUri);
WebResponse response = request.GetResponse();
...that works, but im still wondering -- did this change?
thanks!
sm
Depending on directory structure maybe we need to insert Request.ApplicationPath:
Uri uri = new Uri(authority + Request.ApplicationPath + relativePath);
Didn't test it on 1.0, but is a little bit cumbersome to make it working; I suppose it should be something similar to ResponseRedirect(~/page.aspx)...? you right...
SpaceMarine wrote:
WebRequest & relative paths
19-Mar-09
did something change in the WebRequest object from .NET 1.1 to 2.0?
i swear i used to be able to pass relative URLs into the WebRequest
method, like so:
string relativePath = "/foo/bar.html";
WebRequest request = HttpWebRequest.Create(relativePath);
WebResponse response = request.GetResponse();
....now that generates an exception:
"Invalid URI: The format of the URI could not be determined."
so then i figured out how to create a full URL path ("http://...")
like so:
string relativePath = "/foo/bar.html";
//get the main url
string authority =
System.Web.HttpContext.Current.Request.Url.GetLeftPart
(UriPartial.Authority);
//add the supplied relative path
Uri uri = new Uri(authority + relativePath);
WebRequest request = HttpWebRequest.Create(uri.AbsoluteUri);
WebResponse response = request.GetResponse();
....that works, but im still wondering -- did this change?
thanks!
sm
Previous Posts In This Thread:
On Thursday, March 19, 2009 4:32 AM
SpaceMarine wrote:
WebRequest & relative paths
did something change in the WebRequest object from .NET 1.1 to 2.0?
i swear i used to be able to pass relative URLs into the WebRequest
method, like so:
string relativePath = "/foo/bar.html";
WebRequest request = HttpWebRequest.Create(relativePath);
WebResponse response = request.GetResponse();
....now that generates an exception:
"Invalid URI: The format of the URI could not be determined."
so then i figured out how to create a full URL path ("http://...")
like so:
string relativePath = "/foo/bar.html";
//get the main url
string authority =
System.Web.HttpContext.Current.Request.Url.GetLeftPart
(UriPartial.Authority);
//add the supplied relative path
Uri uri = new Uri(authority + relativePath);
WebRequest request = HttpWebRequest.Create(uri.AbsoluteUri);
WebResponse response = request.GetResponse();
....that works, but im still wondering -- did this change?
thanks!
sm
Submitted via EggHeadCafe - Software Developer Portal of Choice
More Fun with Fluent NHibernate Automapping
http://www.eggheadcafe.com/tutorials/aspnet/50aa9259-6dbb-4d16-9639-81ee42171b00/more-fun-with-fluent-nhib.aspx