2
votes

I am trying to login to a SharePoint website that uses Windows Integrated (NTLM) authentication. There are 2 ways to enter credentials for the SharePoint website, Windows Authentication and form authentication.

However, Form authentication is disable on this specific website and I can only use windows authentication. Is there a way for me to login to this site with different credential than what I used to login to my windows machine?

See error here: Form authentication denied

        String site = "http://sharepoint/";
        ClientContext context = new ClientContext(site);
        context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
        FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");
        context.FormsAuthenticationLoginInfo = formsAuthInfo;

        // The SharePoint web at the URL.
        Web web = context.Web;

        // We want to retrieve the web's properties.
        context.Load(web);

        // Execute the query to the server.
        context.ExecuteQuery();


        InitializeComponent();

I also tried to use: context.Credentials = new NetworkCredential("user", "pass", site);

       ClientContext context = new ClientContext(site);
       context.Credentials = new NetworkCredential("user", "pass", site);


        // The SharePoint web at the URL.
        Web web = context.Web;

        // We want to retrieve the web's properties.
        context.Load(web);

        // Execute the query to the server.
        context.ExecuteQuery();


        InitializeComponent();

I get the following 401 (unauthorized) error

2
You haven't provided any of the code you've tried so far. Are you looking for non-code solutions? In Windows 7, you can run an application using different Windows credentials than those you're logged in with by holding Shift and right-clicking on the executable, then selecting "Run as different user"Thriggle
Hey, Thanks for your comment. I have included my code. Also, I am running windows server 2008 R2 Standard, not windows 7.Rana

2 Answers

2
votes

Instead of changing the ClientContext object's AuthenticationMode property to FormsAuthentication, try setting the object's Credentials property to a valid Network Credential object.

ClientContext context = new ClientContext("http://sharepointsite/");
context.Credentials = new NetworkCredential("username","password","domain");
0
votes

Don't know if it is late but, by default, the managed client object models authenticate users by using their Windows credentials (DefaultCredentials).

So you don't need to explicitly set the Credentials. Just Set following -

context.AuthenticationMode = ClientAuthenticationMode.Default;