Monday, July 16, 2012

Auto user login in ASP.NET site with HttpWebRequest

[Sample of July 13] Auto user login in ASP.NET site with HttpWebRequest:

Homepage image
Sample of the Day RSS Feed
Sample Download : http://code.msdn.microsoft.com/VBASPNETAutoLogin-023c5ab4 

Today’s code sample illustrates how to programmatically log a user into an ASP.NET site using HttpWebRequest Class.

To achieve this, we request the ASP.NET login form by using the HttpWebRequest GET method and get the html code.  Next, we substring the login page html code to get the __VIEWSTATE, __EVENTVALIDATION parameters.  We concat the __VIEWSTATE,__EVENTVALIDATION,Username, password and
loginbutton to the whole string and convert it to byte array.  Last, we submit the request data and get the return data and display it.


imageYou can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage http://1code.codeplex.com/.

No comments:

Post a Comment

Could not find a part of the path ... bin\roslyn\csc.exe

I am trying to run an ASP.NET MVC (model-view-controller) project retrieved from TFS (Team Foundation Server) source control. I have added a...