how to access site content after authentication

  • Thread starter Thread starter ALA
  • Start date Start date
A

ALA

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
 
hmhmm, so there seems to be no way to make something like

WebRequest request = WebRequest.Create(url);
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
 
ok, I got it working...

the cue was that the FormsAuthentication.FormsCookieName property
holds the cookie name of the authenticated user.

HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = new CookieContainer();

HttpCookie authCookie =
HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
request.CookieContainer.Add(new Cookie(authCookie.Name,
authCookie.Value, authCookie.Path, "localhost"));

HttpWebResponse response =
(HttpWebResponse)request.GetResponse();

maybe this'll also help somebody else in the future...

André
 
Back
Top