我有兩個網站,我使用相同的cookie登錄,它工作正常。單點登錄網站 - MVC 3
我遇到的問題是這兩個網站在設計上看起來完全不同,我希望其中一個網站處理登錄功能,另一個只需將用戶名/密碼發佈到另一個網站並在後端創建cookie。
我有這個功能,但問題是如何通知其他網站,登錄已成功或失敗,實際上沒有去其他網站完成登錄過程?
我已經創建了類似這樣的工作正常,但這是我應該如何處理另一個網站上的帖子以及我應該返回的問題作爲回答困惑我的問題。
任何想法或替代解決方案都會對我有很大幫助!
[HttpPost]
public ActionResult FormPost(LogOnModel model)
{
WebRequest request = WebRequest.Create(strServer);
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes("password=" + model.Password);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
TempData["Response"] = responseFromServer;
return View();
聽起來像您可以從共享的[WebService](http://msdn.microsoft.com/zh-cn/library/t745kdsh.aspx)中受益。 – jrummell 2012-03-02 15:13:24