简体   繁体   中英

Windows authentication with SharePoint Web Services via SOAP

I am trying to authenticate my SharePoint service t retrieve SPList Items :

 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;
        }
    }

and it was working fine till today i try to use it again but it return me an eror cookies[result.CookieName] is null , and this only happens on my machine not other machine .

@Eslan May i knw fom where your are calling this code ? from webpart or app or console application ? I suspect its authentication mode issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM