2012-11-19 104 views
0

.aspauth cookie此行之有效的HTTP,但不工作的HTTPS。獲得通過HTTPS

private Cookie GetAuthCookie(string user, string pass) 
    { 
     var http = WebRequest.Create(_baseUrl+"Users/Login") as HttpWebRequest; 
     http.AllowAutoRedirect = false; 
     http.Method = "POST"; 
     http.ContentType = "application/x-www-form-urlencoded"; 
     http.CookieContainer = new CookieContainer(); 
     var postData = "UserName=" + user + "&Password=" + pass + "&RememberMe=true&RememberMe=false&ReturnUrl=www.google.com"; 
     byte[] dataBytes = System.Text.Encoding.UTF8.GetBytes(postData); 
     http.ContentLength = dataBytes.Length; 
     using (var postStream = http.GetRequestStream()) 
     { 
      postStream.Write(dataBytes, 0, dataBytes.Length); 
     } 
     var httpResponse = http.GetResponse() as HttpWebResponse; 
     return httpResponse.Cookies[FormsAuthentication.FormsCookieName]; 
    } 
+1

它可能是一個SSL證書問題,詳見這個問題:http://stackoverflow.com/questions/560804/how-do-i-use-webrequest-to-access-an-ssl-encrypted-site-使用HTTPS的沒錯 – curtisk

+0

...謝謝 – Agzam

+0

我會做出一個答案的版本,收在這個問題上的循環 – curtisk

回答

2

它可能是一個SSL證書的問題,你會看到這樣通過根據與您的證書頒發者的情況Web客戶端或訪問的WebRequest SSL。關於如何解決這個問題,請參閱此前的question for details