2011-11-21 32 views
2

對於我們啓用FBA的SharePoint網站之一,我們需要訪問各種Web服務。我知道我們需要在調用任何其他SP Web服務之前調用Authentication.asmx。從哪裏獲取用於Authentication.asmx的憑證?

如何獲取當前登錄用戶的用戶名&密碼以傳遞給Authentication.asmx服務?

謝謝。

更新:我試着用已知的用戶名和密碼嘗試Marek的解決方案,並獲得了Authentication.asmx的401。所以可能有些設置關閉了。管理員正在研究它。

回答

1
MembershipUser user = Membership.GetUser(); 
string username = user.UserName; 
string password = user.GetPassword(); 

Authentication auth = new Authentication(); 
auth.CookieContainer = new CookieContainer(); 
LoginResult result = auth.Login(username, password); 

if (result.ErrorCode == LoginErrorCode.NoError) 
{ 
    CookieCollection cookies = auth.CookieContainer.GetCookies(new Uri(auth.Url)); 
    Cookie authCookie = cookies[result.CookieName]; 
    Lists lists = new Lists(); 
    lists.CookieContainer = new CookieContainer(); 
    lists.CookieContainer.Add(authCookie); 
    lists.GetListCollection(); 
} 

但是,根據會員提供的設置(存儲的密碼以純文本,加密或散列?是通過安全的答案得到密碼?它需要)取回密碼可能會更加困難甚至不可能,您需要向用戶詢問。

+0

謝謝Marek。我們需要從許多自定義aspx頁面訪問Web服務。 – noobDotNet

+0

PasswordFormat是「哈希」,並且在web.config中將EnablePasswordRetrieval設置爲false。有沒有解決的辦法?謝謝。 – noobDotNet

+0

@noobDotNet從安全的角度來看,對密碼進行散列是最好的選擇,但這也意味着您將無法從數據庫中檢索它們。「您可以使用單個專用帳戶來進行所有Web服務調用? –