title: The remote server returned an error: (401) Unauthorized. Using CSOM in ASP.NET
body: <p>I'm tried to pull some SharePoint 2013 list data I created which works fine when running locally on my machine and when run locally one the server.  I'm user the same credentials when running both locally and locally on the server.  The issue is when I publish and navigate to my ASP.NET app on the server I get the "The remote server returned an error: (401) Unauthorized." Error...</p>
  
  <p>I've looked at a bunch of the posts on stackoverflow and some other articles on the web</p>
  
  <p>This points out that the context seems to be using IUSR:
  <a href="http://blogs.msdn.com/b/sridhara/archive/2014/02/06/sharepoint-2013-csom-call-from-web-part-fails-with-401-for-all-users.aspx" rel="noreferrer">http://blogs.msdn.com/b/sridhara/archive/2014/02/06/sharepoint-2013-csom-call-from-web-part-fails-with-401-for-all-users.aspx</a></p>
  
  <p>This one mentions to try setting the default network credentials:
  <a href="https://sharepoint.stackexchange.com/questions/10364/http-401-unauthorized-using-the-managed-client-object-model">https://sharepoint.stackexchange.com/questions/10364/http-401-unauthorized-using-the-managed-client-object-model</a></p>
  
  <p>I've tried using the fixes mentioned in the article as well as trying to force the context to use DefaultNetworkCredentials but no luck.  I would like for the app to use the credentials of the logged in user and not the machine...</p>
  
  <p>Here is the code I'm using:</p>
  
  <pre><code>        SP.ClientContext context = new SP.ClientContext("MySPDevInstance");
          context.Credentials = CredentialCache.DefaultNetworkCredentials;
  
          Entity entity = context.Web.GetEntity(collectionNamespace, collectionName);
          LobSystem lobSystem = entity.GetLobSystem();
          LobSystemInstanceCollection lobSystemInstanceCollection = lobSystem.GetLobSystemInstances();
  
          context.Load(lobSystemInstanceCollection);
          context.ExecuteQuery();
  
          LobSystemInstance lobSystemInstance = lobSystemInstanceCollection[0];
          FilterCollection filterCollection = entity.GetFilters(filter);
  
          filterCollection.SetFilterValue("LimitFilter", 0, 1000);
  
          EntityInstanceCollection items = entity.FindFiltered(filterCollection, filter, lobSystemInstance);
  </code></pre>
  
  <p>The server is running IIS 6.0</p>
  
  <p>Any advice would be much appreciated!</p>
  
  <p>Thank you</p>