通过SOAP使用SharePoint Web Services进行Windows身份验证

时间:2016-02-04 08:48:05

标签: c# sharepoint sharepoint-2010

我正在尝试验证我的SharePoint服务,检索SPList项目:

 private Cookie AuthenticateFBASite(string AuthenticationSiteURL, string UserName, string Password, NetworkCredential nc2)
    {
        Cookie CurrentSiteCookie = null;
        using (Authentication.Authentication authSvc = new Authentication.Authentication())
        {
            authSvc.Url = AuthenticationSiteURL + "/_vti_bin/authentication.asmx";
            authSvc.CookieContainer = new System.Net.CookieContainer();     //create a new cookie container
            //set the FBA login information

            authSvc.AllowAutoRedirect = true;
            authSvc.PreAuthenticate = true;

            authSvc.Credentials = nc2;
            Authentication.LoginResult result = authSvc.Login(UserName, Password);
            if (result.ErrorCode == Authentication.LoginErrorCode.NoError)
            {
                try
                {
                    CookieCollection cookies = authSvc.CookieContainer.GetCookies(new Uri(AuthenticationSiteURL));
                    CurrentSiteCookie = cookies[result.CookieName];
                    return CurrentSiteCookie;
                }
                catch (System.Exception ex)
                {
                    //Console.WriteLine("Exception occured while calling lists.asmx" + ex.Message);
                    return CurrentSiteCookie;
                }
            }
            else if (result.ErrorCode == Authentication.LoginErrorCode.PasswordNotMatch)
            {

                              return CurrentSiteCookie;
            }
            else
                return CurrentSiteCookie;
        }
    }

它工作正常,直到今天我再次尝试使用它,但它返回一个错误cookies[result.CookieName]为空,这只发生在我的机器而不是其他机器上。

1 个答案:

答案 0 :(得分:0)

@Eslan我可以知道你在调用这段代码的地方吗?来自webpart或应用程序或控制台应用程序?我怀疑它的身份验证模式问题。