Password richiesta?Il server remoto ha restituito un errore: (401) non autorizzato
-
10-12-2019 - |
Domanda
Sto provando a fare riferimento a una voce di elenco di SharePoint nella mia pagina ASPX utilizzando il modello oggetto client SharePoint. Sono stato concesso i privilegi del "controllo completo" su questo elenco. Il problema è che posso compilare solo la richiesta quando ho impostato il clientcontext.credentials esplicitamente con la mia password hard-codificata nella pagina. Ovviamente non voglio visitatori al mio sito per avere l'accesso a cose in base alle mie credenziali.
Questo lo fa funzionare ma non soddisfa i requisiti del progetto:
ClientContext cc = new ClientContext("http://sharepoint.site.com/sitename");
cc.Credentials = new NetworkCredential("username", "password", "domain");
.
Ho messo nel web.config e sembra funzionare bene. Quando controllo WindowsIdentity.GetCurrent().Name
mostra la mia corretta informazione "dominio \ username", che penso dovrebbe significare che le mie credenziali siano valide. Perché, allora, è SharePoint respingendo il cc.ExecuteQuery();
con A "System.net.WebException il server remoto ha restituito un errore: (401) non autorizzato."?
Posso inserire una casella di testo sullo schermo che consente all'utente di immettere la propria password per creare un oggetto networkcredire, ma posso dirti in questo momento il cliente (il mio capo) non sarà felice con questo e sta andando Dimmi che vuole che trovi un lavoro in giro.
Modifica: Il sito di SharePoint è ospitato su un sito diverso, ma all'interno della stessa azienda intranet.
Soluzione
Are you using kerberos, ntlm, forms or claims? My guess is you are using NTLM and running into the NTLM double hop "issue".
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/
Altri suggerimenti
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.