none
The remote server returned an error(401) unauthorized RRS feed

  • Question

  • I have created one windows service, which reads data from SharePoint 2013 list and save to Database table. I have two web front end server WFE1 and WFE2. I have hosted windows service on WFE1 only. Also I have configured failover cluster. When WFE1 restarts or down WFE2 gets up. I am reading data using CSOM and using service account for authentication , which is having admin access. My code works fine If WFE1 is selected as a primary. However if I restart WFE1 and WFE2 gets primary. My code not working and it is giving me The remote server returned an error(401) unauthorized error. I have a secured https protocol URL. The service account having same access on both the server. I am looking for solution from a long time. Can any one please help me on this?
    Tuesday, February 14, 2017 4:56 PM

All replies

  • Hi,

    Please add credentials to the clientContext and use an admin user for authentication.

    System.Net.NetworkCredential credential = new System.Net.NetworkCredential("username", "password","domain"); 
    ClientContext clientContext = new ClientContext(siteURL);
    clientContext.Credentials = credential;

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, February 15, 2017 9:14 AM
    Moderator
  • I have already added credentials to the clientcontext. In my case it is working fine when my WFE1 is selected as a primary. if I restart WFE1 and WFE2 gets primary the windows service returning the remote server returned an error 401 unauthorized.
    Thursday, February 16, 2017 5:35 AM
  • Hi,

    What is the difference of WFE1 and WFE2 settings?

    Or check the article below:

    http://sharepointconnoisseur.blogspot.sg/2011/04/how-to-resolve-401-unauthorized-error.html

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, February 16, 2017 9:05 AM
    Moderator