Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying reference a sharepoint list item in my aspx page using the Sharepoint Client Object Model. I have been granted 'Full Control' privileges on this list. The problem is that I can only complete the request when I set the ClientContext.Credentials explicitly with my password hard-coded into the page. Obviously I don't want visitors to my site to have the access to things based on my credentials.

This gets it to work but does not meet the project requirements:

ClientContext cc = new ClientContext("http://sharepoint.site.com/sitename");
cc.Credentials = new NetworkCredential("username", "password", "domain");

I have set in the web.config and seems to be working fine. When I check WindowsIdentity.GetCurrent().Name it shows my correct "domain\username" information, which I think should mean my credentials are valid. Why then, is SharePoint rejecting the cc.ExecuteQuery(); with a "System.Net.WebException The remote server returned an error: (401) Unauthorized."?

I can put a textbox on the screen that lets the user enter their password to used to create a NetworkCredential object, but I can tell you right now the customer (my Boss) is not going to be happy with this and is going tell me he wants me to find a work around.

Edit: The sharepoint site is hosted on a different site, but within the same company intranet.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Are you using kerberos, ntlm, forms or claims? My guess is you are using NTLM and running into the NTLM double hop "issue".

http://blogs.msdn.com/b/besidethepoint/archive/2010/05/09/double-hop-authentication-why-ntlm-fails-and-kerberos-works.aspx

The easiest next step is probably to change your site over to Kerberos. I have a blog article where I outlined some resources that help when setting up kerberos in SharePoint.

http://steve.thelineberrys.com/resources-for-setting-up-kerberos-authentication-in-sharepoint/

share|improve this answer
    
Yeah, Its NTLM. I'm looking into your suggestions. I'll comment here if anything comes from it. Otherwise assume that the Kerberos approach was denied due to the policies of the IT department and not because your answer was flawed in any way. –  Rex NFX Feb 26 '13 at 22:28

Have you tried using DefaultCredentials instead, to pick up the identity of the current user?

Additionally: is this aspx running within your SharePoint site? If so, why are you using the Client Object Model? Just use the server OM. Far easier and much less hassle.

share|improve this answer
    
I did try CredentialCache.DefaultCredentials. It didn't help. The sharepoint site is on a different server, but within the same company intranet. When I create an aspx page on the sharepoint site with the designer, it won't let me edit any of the asp.net code. –  Rex NFX Feb 26 '13 at 15:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.