2011-11-21 33 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服务调用? –