Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

how to access site content after authentication

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ALA - 06 Oct 2007 18:48 GMT
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
Peter Bromberg [C# MVP] - 06 Oct 2007 19:03 GMT
You would need to log in by making a form post identical to the one at the
Login page, and pass the cookie Collection with your subsequent requests, as
it contains the cookie with the FormsAuthentication Ticket.
-- Peter
Recursion: see Recursion
site:  http://www.eggheadcafe.com
unBlog:  http://petesbloggerama.blogspot.com
BlogMetaFinder:    http://www.blogmetafinder.com

> Hello,
>
[quoted text clipped - 26 lines]
>
> Andre
ALA - 06 Oct 2007 19:44 GMT
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
ALA - 07 Oct 2007 12:13 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.