Skip to main content
added 413 characters in body
Source Link
Ali Jafer
  • 17.8k
  • 1
  • 28
  • 41

you need cookies as its used for form autentication:

The FormsAuthenticationLoginInfo class is used by the ClientContext.FormsAuthenticationLogin method by first calling the EnsureLogin method to check for authentication cookies.

more detailed info can be found here: goto Authentication section!

http://www.codeproject.com/Articles/268193/SharePoint-2010-Client-Object-Model-Part-1

taken from link above from fiddler you can see where its setting the cookie authentication in bold

HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json

Server: Microsoft-IIS/7.5

SPRequestGuid: 22e3f795-a5c9-492d-a551-3e950b8f1c10

Set-Cookie: WSS_KeepSessionAuthenticated={4e4cffb3-203e-4857-8f5a-90a4b18789a4}; path=/

X-SharePointHealthScore: 0

X-Content-Type-Options: nosniff

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

MicrosoftSharePointTeamServices: 14.0.0.6029

Content-Length: 460

EDIT

Ok so now i know your using windows authentication you need to send the credentails using the following:

clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;

FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");

clientContext.FormsAuthenticationLoginInfo = formsAuthInfo;

in your case:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
    FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUserName", "MyUserPassword");
    context.FormsAuthenticationLoginInfo = formsAuthInfo;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

or anonymous user:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.Anonymous;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

http://msdn.microsoft.com/en-us/library/office/ee535729(v=office.14).aspx

EDIT 2

lol your not making it easy!

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.Credentials = new NetworkCredential("userName", "Userpassword", "domain");
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

you need cookies as its used for form autentication:

The FormsAuthenticationLoginInfo class is used by the ClientContext.FormsAuthenticationLogin method by first calling the EnsureLogin method to check for authentication cookies.

more detailed info can be found here: goto Authentication section!

http://www.codeproject.com/Articles/268193/SharePoint-2010-Client-Object-Model-Part-1

taken from link above from fiddler you can see where its setting the cookie authentication in bold

HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json

Server: Microsoft-IIS/7.5

SPRequestGuid: 22e3f795-a5c9-492d-a551-3e950b8f1c10

Set-Cookie: WSS_KeepSessionAuthenticated={4e4cffb3-203e-4857-8f5a-90a4b18789a4}; path=/

X-SharePointHealthScore: 0

X-Content-Type-Options: nosniff

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

MicrosoftSharePointTeamServices: 14.0.0.6029

Content-Length: 460

EDIT

Ok so now i know your using windows authentication you need to send the credentails using the following:

clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;

FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");

clientContext.FormsAuthenticationLoginInfo = formsAuthInfo;

in your case:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
    FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUserName", "MyUserPassword");
    context.FormsAuthenticationLoginInfo = formsAuthInfo;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

or anonymous user:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.Anonymous;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

http://msdn.microsoft.com/en-us/library/office/ee535729(v=office.14).aspx

you need cookies as its used for form autentication:

The FormsAuthenticationLoginInfo class is used by the ClientContext.FormsAuthenticationLogin method by first calling the EnsureLogin method to check for authentication cookies.

more detailed info can be found here: goto Authentication section!

http://www.codeproject.com/Articles/268193/SharePoint-2010-Client-Object-Model-Part-1

taken from link above from fiddler you can see where its setting the cookie authentication in bold

HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json

Server: Microsoft-IIS/7.5

SPRequestGuid: 22e3f795-a5c9-492d-a551-3e950b8f1c10

Set-Cookie: WSS_KeepSessionAuthenticated={4e4cffb3-203e-4857-8f5a-90a4b18789a4}; path=/

X-SharePointHealthScore: 0

X-Content-Type-Options: nosniff

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

MicrosoftSharePointTeamServices: 14.0.0.6029

Content-Length: 460

EDIT

Ok so now i know your using windows authentication you need to send the credentails using the following:

clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;

FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");

clientContext.FormsAuthenticationLoginInfo = formsAuthInfo;

in your case:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
    FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUserName", "MyUserPassword");
    context.FormsAuthenticationLoginInfo = formsAuthInfo;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

or anonymous user:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.Anonymous;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

http://msdn.microsoft.com/en-us/library/office/ee535729(v=office.14).aspx

EDIT 2

lol your not making it easy!

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.Credentials = new NetworkCredential("userName", "Userpassword", "domain");
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}
added 1376 characters in body
Source Link
Ali Jafer
  • 17.8k
  • 1
  • 28
  • 41

you need cookies as its used for form autentication:

The FormsAuthenticationLoginInfo class is used by the ClientContext.FormsAuthenticationLogin method by first calling the EnsureLogin method to check for authentication cookies.

more detailed info can be found here: goto Authentication section!

http://www.codeproject.com/Articles/268193/SharePoint-2010-Client-Object-Model-Part-1

taken from link above from fiddler you can see where its setting the cookie authentication in bold

HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json

Server: Microsoft-IIS/7.5

SPRequestGuid: 22e3f795-a5c9-492d-a551-3e950b8f1c10

Set-Cookie: WSS_KeepSessionAuthenticated={4e4cffb3-203e-4857-8f5a-90a4b18789a4}; path=/

X-SharePointHealthScore: 0

X-Content-Type-Options: nosniff

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

MicrosoftSharePointTeamServices: 14.0.0.6029

Content-Length: 460

EDIT

Ok so now i know your using windows authentication you need to send the credentails using the following:

clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;

FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");

clientContext.FormsAuthenticationLoginInfo = formsAuthInfo;

in your case:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
    FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUserName", "MyUserPassword");
    context.FormsAuthenticationLoginInfo = formsAuthInfo;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

or anonymous user:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.Anonymous;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

http://msdn.microsoft.com/en-us/library/office/ee535729(v=office.14).aspx

you need cookies as its used for form autentication:

The FormsAuthenticationLoginInfo class is used by the ClientContext.FormsAuthenticationLogin method by first calling the EnsureLogin method to check for authentication cookies.

more detailed info can be found here: goto Authentication section!

http://www.codeproject.com/Articles/268193/SharePoint-2010-Client-Object-Model-Part-1

taken from link above from fiddler you can see where its setting the cookie authentication in bold

HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json

Server: Microsoft-IIS/7.5

SPRequestGuid: 22e3f795-a5c9-492d-a551-3e950b8f1c10

Set-Cookie: WSS_KeepSessionAuthenticated={4e4cffb3-203e-4857-8f5a-90a4b18789a4}; path=/

X-SharePointHealthScore: 0

X-Content-Type-Options: nosniff

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

MicrosoftSharePointTeamServices: 14.0.0.6029

Content-Length: 460

you need cookies as its used for form autentication:

The FormsAuthenticationLoginInfo class is used by the ClientContext.FormsAuthenticationLogin method by first calling the EnsureLogin method to check for authentication cookies.

more detailed info can be found here: goto Authentication section!

http://www.codeproject.com/Articles/268193/SharePoint-2010-Client-Object-Model-Part-1

taken from link above from fiddler you can see where its setting the cookie authentication in bold

HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json

Server: Microsoft-IIS/7.5

SPRequestGuid: 22e3f795-a5c9-492d-a551-3e950b8f1c10

Set-Cookie: WSS_KeepSessionAuthenticated={4e4cffb3-203e-4857-8f5a-90a4b18789a4}; path=/

X-SharePointHealthScore: 0

X-Content-Type-Options: nosniff

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

MicrosoftSharePointTeamServices: 14.0.0.6029

Content-Length: 460

EDIT

Ok so now i know your using windows authentication you need to send the credentails using the following:

clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;

FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");

clientContext.FormsAuthenticationLoginInfo = formsAuthInfo;

in your case:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
    FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUserName", "MyUserPassword");
    context.FormsAuthenticationLoginInfo = formsAuthInfo;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

or anonymous user:

using (var context = new ClientContext("http:\\WebApplicationURL"))
{
    context.AuthenticationMode = ClientAuthenticationMode.Anonymous;
    var site = context.Web;
    context.Load(site, s => s.Title);
    context.ExecuteQuery();
    Console.WriteLine(site.Title);
    Console.ReadLine();
}

http://msdn.microsoft.com/en-us/library/office/ee535729(v=office.14).aspx

Source Link
Ali Jafer
  • 17.8k
  • 1
  • 28
  • 41

you need cookies as its used for form autentication:

The FormsAuthenticationLoginInfo class is used by the ClientContext.FormsAuthenticationLogin method by first calling the EnsureLogin method to check for authentication cookies.

more detailed info can be found here: goto Authentication section!

http://www.codeproject.com/Articles/268193/SharePoint-2010-Client-Object-Model-Part-1

taken from link above from fiddler you can see where its setting the cookie authentication in bold

HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json

Server: Microsoft-IIS/7.5

SPRequestGuid: 22e3f795-a5c9-492d-a551-3e950b8f1c10

Set-Cookie: WSS_KeepSessionAuthenticated={4e4cffb3-203e-4857-8f5a-90a4b18789a4}; path=/

X-SharePointHealthScore: 0

X-Content-Type-Options: nosniff

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

MicrosoftSharePointTeamServices: 14.0.0.6029

Content-Length: 460