ASP.NET to Wordpress SSO with HttpWebRequest

前端 未结 1 1018
栀梦
栀梦 2020-12-15 14:51

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

1条回答
  •  囚心锁ツ
    2020-12-15 15:25

    From what I can see, your server side code is submitting the request to wp-load.php which is creating and logging the user in (in the session of the server side web request).

    I beleive that wordpress will send back a cookie on each page, so you would have to extract the cookies from the WebResponse, and send those cookies back from your asp.net page, along with a

    Response.Redirect("http://localhost:1350/wp/");

    I am unable to test this as I don't have a WP install at the moment, and I don't use VB.net but i guess it would go something like:

    Dim cookies As New CookieContainer()
    Dim myRequest As HttpWebRequest = WebRequest.Create("http://localhost:1350/wpComm/createWPaccount.php") 
    myRequest.Method = "POST" 
    myRequest.ContentType = "application/x-www-form-urlencoded" 
    myRequest.ContentLength = data.Length 
    myRequest.CookieContainer = cookies;    
    Dim newStream As Stream = myRequest.GetRequestStream() 
    
    newStream.Write(data, 0, data.Length) 
    newStream.Close() 
    
    For Each c As Cookie In cookies 
      Response.Cookies.Add(c)
    Next 
    
    Response.Redirect("http://localhost:1350/wp/")
    

    0 讨论(0)
提交回复
热议问题