ASP.NET - How to login to some web site from my own one

Asked By mostafa hamdy on 12-Jul-11 11:53 AM
Hello all
I have some web site built in 4, and I  want to create some Icon on my site to Yahoo mail , Facebook or what ever the site and when I click this Icon I want to login directly to my account in this site with out entering my login info, sure I will register my login data for every site  of them have an Icon, please If any body get what I mean and can help me in doing that please send me
Ravinder Jamgotre replied to mostafa hamdy on 12-Jul-11 12:03 PM

you need to use forms authentication and define the username and password for the web url you are attempting to goto; this will pass through the required credentails and allow access. Seems like you are trying to use SSO. there are other solution my onelogin on the web offering clould authentication services. I do not have the code to do this as I found using third party tools was much cleaner. However maybe this site can help further.
dipa ahuja replied to mostafa hamdy on 12-Jul-11 12:14 PM
Untitled document
you can add this code to share to any social networking sites from

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
<script type="text/javascript" src=""></script>
<!-- AddThis Button END -->

Ravi S replied to mostafa hamdy on 12-Jul-11 02:03 PM

Don't think of it so much as going to the page and filling stuff in. You're going to need to create a that contains the proper HTTP headers and data, that will look to their server to be someone that filled everything in. You'll need to look at the site you're trying to do this with for specifics, but I'd assume they're sending over a set of POST data when you click sign in. Example, pulled from MSDN and modified to be closer what you need (first few lines):

WebRequest request = WebRequest.Create ("http:/");
.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "username=blah;password=blah";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
= response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
.Close ();
.Close ();
.Close ();
Jitendra Faye replied to mostafa hamdy on 13-Jul-11 12:46 AM

Giving you example in one way is possible that -
Sharing Authentication Between Applications

There is nothing to do with coding,we just need to select both websites/application and assign them same pool on IIS Server,Apart you need to make some changes on WebConfig,which you can check on same thread.

Hope this will help you.

mostafa hamdy replied to Ravi S on 18-Jul-11 08:17 AM
Hello Ravi
at the beginning many thanx about your code segment really it helped my so much, but after I write it down with some modifications ,It just open the login page which I pass to it with out doing any login , the code I have done is as the following:

      string LOGIN_URL = "";

      string USERNAME = "";

      string PASSWORD = "mypassword";



      HttpWebRequest webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;

      StreamReader responseReader = new StreamReader(



      string responseData = responseReader.ReadToEnd();



      string postData = ";pass=ekramhamdy";

      byte[] byteArray = Encoding.UTF8.GetBytes(postData);


CookieContainer cookies = new CookieContainer();

      webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;

      webRequest.Method = "POST";

      webRequest.ContentType = "application/x-www-form-urlencoded";

      webRequest.CookieContainer = cookies;

      StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());




      SECRET_PAGE_URL = "!/profile.php?id=100001740129596";

      webRequest = WebRequest.Create(SECRET_PAGE_URL) as HttpWebRequest;

      webRequest.CookieContainer = cookies;

      responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());

      responseData = responseReader.ReadToEnd();



please if you get why this code stop at the login page and dont do on on the loging process please send me or tell me about some url may help me in completing that
thanx again 
best regards