Question

Locked

Getting login page in HttpWebResponse after providing credentials?

By stykfigure ·
I am fairly new to .NET programming, so I apologize if any of this request is inaccurate or just plain silly.
I have setup a couple of forms (1 login, 1 "muscle"). UserName & Password are being collected by the login form and passed to the "muscle" for use in accessing a website.

I have verified that the correct credentials are being passed.

The problem that I am having, is that when I use "HttpWebRequest" to connect to the site, I am just getting the login page from the "HttpWebResponse".

I am using a valid UserName & Password for the site, but I don't think I am passing the
credentials correctly.

When browsing the site, it keeps the authentication cached so a user almost never has to
re-authenticate and I was trying to find a way to use my already cached credentials, but have failed thus far.

I have also tried using the below code just to cover all the bases I could find by researching HELP and some web resources.

I created a WebBrowser on a form and pointed it to the ProfileLink location and it returned the same login page.

After logging into the host site on the WebBrowser, closing the form then rerunning the "gather" part of the code it returned the same LoginPage via HttpWebResponse, but the WebBrowser on the form loaded the correct page.

I'm really stuck on this one. I have all the other functionality of the script taken care of, but I just can't get it to accept the supplied credentials.

It always returns a LoginPage.

Basically the rest of the script parses the returned page for some keywords then uses that information to create a new HTML page that contains the ProfileName, displays the ProfileAvatar, and has a list of all community accomplishments.
Any help would be GREATLY appreciated as I've been beating my head against a brick wall for about 2 days now researching along with trial and error, but I just can't seem to figure it out.


THANK YOU in advance for any help!

Confused Newbie


Particulars:
* Target Pages are in PHP
* I'm using .NET 2005 Studio (VB) on an XP box w/ 2GB RAM
* 1st time scripting an HTTP/Network type resource where "RunAs" can't be used.
* Fairly extensive IT (Hardware/Network/Software troubleshooting) background.
* Have scripted numerous small scale admin type tasks, so somewhat knowledgable on VB.
* Please let me know if you need any additional information.


ProfileLink = tbProfileLink.Text            'User provided Http address to a profile on the host site.
UserName = frmLogin.tbUserName.Text        'User provided login name for the host site.
UserPassword = frmLogin.tbUserPassword.Text    'User provided password for the host site.
       
'Doubt I need Digest, NTLM or Kerberose, but they are here because I've tried just about 'everything I can think of.
Dim myCache As New CredentialCache
myCache.Add(New Uri("http://kofk.de/"), "Basic", New NetworkCredential( _

UserName, UserPassword))
myCache.Add(New Uri("http://kofk.de/"), "Digest", New NetworkCredential( _

UserName, UserPassword))
myCache.Add(New Uri("http://kofk.de/"), "Negotiate", New NetworkCredential( _

UserName, UserPassword))
myCache.Add(New Uri("http://kofk.de/"), "NTLM", New NetworkCredential( _

UserName, UserPassword))
myCache.Add(New Uri("http://kofk.de/"), "Kerberose", New NetworkCredential( _

UserName, UserPassword))

Dim HttpWReq As HttpWebRequest = _
            CType(WebRequest.Create(ProfileLink), HttpWebRequest)

HttpWReq.Credentials = myCache    'Automatically parses credentials and uses

                                                     'the appropriate one?


HttpWReq.AutoAuthenticate = True

 Dim HttpWResp As HttpWebResponse = _
                CType(HttpWReq.GetResponse(), HttpWebResponse)

        '[All code past here seems to be functioning properly.]

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums