<pre lang="c#"> public void LoginToWordpress() { //This enables single sign on between our asp.net site and wordpress. try { //get the values string uid = TextBox1.Text; string pwd = TextBox2.Text; Session["uid"]=TextBox1.Text; Session["pwd"] = TextBox2.Text; //format and encode the input data ASCIIEncoding encoding = new ASCIIEncoding(); string postData = ("user_login=" + uid); postData += ("user_pass=" + pwd); byte[] data = encoding.GetBytes(postData); CookieContainer cc = new CookieContainer(); //Prepare web request... HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://mysite.com/blog/wp-admin/"); myRequest.Method = WebRequestMethods.Http.Get; myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.ContentLength = data.Length; myRequest.CookieContainer = cc; Stream newStream = myRequest.GetRequestStream(); //submit the php form for BuddyPress signup newStream.Write(data, 0, data.Length); newStream.Close(); //Get the response HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream()); String adv=reader.ReadToEnd(); HttpCookie aCookie,VCookie,Dcookie,PCookie; string cookieName,cookievalue,cookiedomain,cookiepath; int limit = myResponse.Cookies.Count; for (int i = 0; i < limit; i++) { cookieName = myResponse.Cookies[i].Name; cookievalue = myResponse.Cookies[i].Value; cookiedomain = myResponse.Cookies[i].Domain; cookiepath = myResponse.Cookies[i].Path; aCookie = new HttpCookie(cookieName); VCookie = new HttpCookie(cookievalue); Dcookie = new HttpCookie(cookiedomain); PCookie = new HttpCookie(cookiepath); Response.Cookies.Add(aCookie); Response.Cookies.Add(VCookie); Response.Cookies.Add(Dcookie); Response.Cookies.Add(PCookie); } } catch (Exception ex) { Response.Write(ex); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)