1

I'm trying to pull data through SharePoint 2013 BDC Models that I have imported from my ASP.NET application which works fine when I run either locally on my machince or locally on the server. However, when I deploy this web app to the web server I get "The remote server returned an error:

(401) Unauthorized." error.

I posted this issue on StackOverflow:

https://stackoverflow.com/questions/22841115/the-remote-server-returned-an-error-401-unauthorized-using-csom-in-asp-net

Code I'm using is here:

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

I learned that there is an issue due to the double hop... Credentials being lost on the second hop because the web app server and the SharePoint server don't trust each other. So as recommended in that thread I asked our SharePoint admin to setup Kerberos between the two servers.

Here is the guide I sent to our admin:

http://blog.blksthl.com/2012/09/26/the-first-kerberos-guide-for-sharepoint-2013-technicians/

After setting up Kerberos we started getting a new error when deploying to the web server "target principal name is incorrect" and now when I run the code locally on my machine I get "The remote server returned an error: (401) Unauthorized."

I tried forcing NTLM in my code:

SP.ClientContext context = new SP.ClientContext("http://MySPDevServer");

CredentialCache cc = new CredentialCache();
cc.Add(new Uri("http://MySPDevServer"), "NTLM", CredentialCache.DefaultNetworkCredentials);

context.Credentials = cc;
context.AuthenticationMode = SP.ClientAuthenticationMode.Default;

This got the code working again on my machine locally but now when I try and deploy to the web server I get a different error "Access denied. You do not have permission to perform this action or access this resource." So I thought I would try and change the authentication type from NTLM to Kerberos and that unfortunately ended in getting the "The remote server returned an error: (401) Unauthorized." error everywhere...

I've looked around all over this site and the web and seen may people with similar issues and have tried many different ways with no luck.

Any help or advice would be very much appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.