Forms Authentication Problem with WebRequest (Tried Everything)

T

Tom Cunningham

Hello, all,

I have done my homework, but I can not get my webrequest to access a
page which is protected by forms authentication. As other posters
have suffered, so have I retrieved only the log in page.

My problem is that I have tried to set the credentials with the
username and password that are in the user node of the web.config
file. I have tried also to use the FormsAuthentication.SetAuthCookie
method. I do not know what I am doing wrong. I am developing
locally: is it possible that using localhost is the problem? I have
also tried to use 127.0.0.1.

Below is a code snippet:

Dim lcUrl As String = "http://localhost/sitename/page.aspx?userid=27"
Dim loHttp2 As HttpWebRequest = WebRequest.Create(lcUrl)
loHttp2.Credentials = New NetworkCredential("username", "password")
Dim loWebResponse2 As HttpWebResponse = loHttp2.GetResponse()
Dim enc2 As Encoding = Encoding.GetEncoding(1252) 'Windows default
Code Page
Dim loResponseStream2 As StreamReader = New
StreamReader(loWebResponse2.GetResponseStream(), enc2)
Dim lcHtml2 As String = loResponseStream2.ReadToEnd()
loWebResponse2.Close()
loResponseStream2.Close()
Label1.Text = lcHtml2

I am sticking the pulled HTML into a label, just to see if it works.
I get the log in page every time.

Any insights? Help would be much appreciated.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,099
Messages
2,570,626
Members
47,237
Latest member
David123

Latest Threads

Top