{"id":7314,"date":"2014-06-07T02:24:27","date_gmt":"2014-06-07T02:24:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/06\/07\/asp-net-to-wordpress-sso-with-httpwebrequest-collection-of-common-programming-errors\/"},"modified":"2014-06-07T02:24:27","modified_gmt":"2014-06-07T02:24:27","slug":"asp-net-to-wordpress-sso-with-httpwebrequest-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/06\/07\/asp-net-to-wordpress-sso-with-httpwebrequest-collection-of-common-programming-errors\/","title":{"rendered":"ASP.NET to WordPress SSO with HttpWebRequest-Collection of common programming errors"},"content":{"rendered":"<p>I am attempting to create a single sign on experience between an asp.net site and a wordpress site using a simple form POST method. I have built a simple php page that uses the native wordpress functions wp_insert_user and wp_signon to create user account in the mysql db and sign them in. In my asp.net &#8216;create new user&#8217; page code behind, I&#8217;m using the post method of an HttpWebRequest to send the required information to the php page.<\/p>\n<p>It almost works! The new wordpress user is created in the mysql database, but they are not logged in. How can I get wordpress to log them in?<\/p>\n<p><strong>UPDATE 11\/29\/11. I&#8217;ve added the code I used to get this working. See below<\/strong><\/p>\n<p>Here is my HttpWebRequest<\/p>\n<pre><code>        Public Sub LoginToWordpress()\n        'This enables single sign on between our asp.net site and wordpress.\n        Try\n            'get the values\n            Dim uid As String = TxtLogin.Text\n            Dim pwd As String = TxtPassword.Text\n\n            'format and encode the input data\n            Dim encoding As New ASCIIEncoding()\n            Dim postData As String = (\"&amp;UserName=\" &amp; uid)\n            postData += (\"&amp;Pwd=\" &amp; pwd)\n            Dim data As Byte() = encoding.GetBytes(postData)\n            Dim cc As New CookieContainer()\n\n            'Prepare web request...\n            Dim myRequest As HttpWebRequest = WebRequest.Create(\"http:\/\/www.mywebsite.com\/speciallogin.php\")\n            myRequest.Method = WebRequestMethods.Http.Get\n            myRequest.Method = \"POST\"\n            myRequest.ContentType = \"application\/x-www-form-urlencoded\"\n            myRequest.ContentLength = data.Length\n            myRequest.CookieContainer = cc\n            Dim newStream As Stream = myRequest.GetRequestStream()\n\n            'submit the php form for BuddyPress signup\n            newStream.Write(data, 0, data.Length)\n            newStream.Close()\n\n            'Get the response\n            Dim myResponse As HttpWebResponse = myRequest.GetResponse()\n            Dim reader As New StreamReader(myResponse.GetResponseStream())\n\n            'Look for cookies in the response\n            If Not myResponse.Cookies.Count = 0 Then\n                For Each c As Cookie In myResponse.Cookies\n\n                    'Write the wordpress cookie to the browser\n                    Dim cookiename As String = c.Name\n                    Dim cCookie As New HttpCookie(cookiename)\n                    cCookie.Value = c.Value\n                    cCookie.Expires = c.Expires\n                    cCookie.Domain = \".mywebsite.com\"\n                    cCookie.Path = \"\/\"\n                    Response.Cookies.Add(cCookie)\n                Next\n            End If\n            myResponse.Close()\n\n        Catch ex As Exception\n            Response.Write(ex)\n        End Try\n    End Sub\n<\/code><\/pre>\n<p>Here is the php page (speciallogin.php)<\/p>\n<pre><code>    \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I am attempting to create a single sign on experience between an asp.net site and a wordpress site using a simple form POST method. I have built a simple php page that uses the native wordpress functions wp_insert_user and wp_signon to create user account in the mysql db and sign them in. In my asp.net [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7314","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7314"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7314\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}