
 Rank: Guest Groups: Guest
Joined: 9/17/2007 Posts: 11,670 Points: -1,200
|
Date parsed: 06/10/2007 03:48:20 Date: Sat, 06 Oct 2007 10:48:20 -0700
Hello,
I've got the following problem: I would like to programmatically read the content of a XHTML page that is only accessible by authorized users after a specific user has passed the authorization (authentication mode: forms). So let's say I've got a site "login.aspx" where the user logs in, another site "page1.aspx" in a directory "mydir" that is only accessible by authenticated users and another site "page2.aspx" in the same directory where I want to load the xhtml output from page1.aspx, e.g. by using XmlDocument.load("http://myserver.com/mydir/page1.aspx").
Unfortunately, the loaded XmlDocument only contains the content of the login page "login.aspx" which is logical for me because the ASP.NET user is different from the user that logged in some minutes before. On the other hand, the human user is still logged in and can access "page1.aspx" whenever he wants by clicking on a certain link inside the browser side.
So my question ... is there a way how I can access the user-dependent data from "page1.aspx" from the code of "page2.aspx" with the authentication information of the human user that's authenticated, e.g. by using the Response.Body - Property or something like that? Maybe it's too easy so that I cannot see a solution ... or also impossible. Thanks for the help.
Background is that I want to write a Semantic Web application where page2.aspx has to read the RDFa content of page1.aspx ...
Andre
|

 Rank: Guest Groups: Guest
Joined: 9/17/2007 Posts: 11,670 Points: -1,200
|
Date parsed: 06/10/2007 04:44:02 Date: Sat, 06 Oct 2007 11:44:02 -0700
hmhmm, so there seems to be no way to make something like
WebRequest request = WebRequest.Create(url);
>> request.Credentials = {the authentication information of the user who just logged in} <<
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd();
XmlDocument xml = new XmlDocument(); xml.LoadXml(responseFromServer);
?
thanks a lot
Andre
|

 Rank: Guest Groups: Guest
Joined: 9/17/2007 Posts: 11,670 Points: -1,200
|
Date parsed: 06/10/2007 21:13:05 Date: Sun, 07 Oct 2007 04:13:05 -0700
ok, I got it working...
the cue was that the FormsAuthentication.FormsCookieName property holds the cookie name of the authenticated user.
HttpWebRequest request =3D (HttpWebRequest)WebRequest.Create(url); request.CookieContainer =3D new CookieContainer();
HttpCookie authCookie =3D HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; request.CookieContainer.Add(new Cookie(authCookie.Name, authCookie.Value, authCookie.Path, "localhost"));
HttpWebResponse response =3D (HttpWebResponse)request.GetResponse();
maybe this'll also help somebody else in the future...
Andr=E9
|