Home > SharePoint > Windows authentication on another server

Windows authentication on another server

2010/11/28

Developing software on a MOSS server ,that interfaces with SharePoint host by web services ,tipically the code is:

svrMoss.Lists objProxy = new svrMoss.Lists();
objProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

In our example svrMoss is the variable assigned is created the web service reference, by attaching  to

http://svrMoss:<port>/_vti_bin/lists.asmx

But if we are outside the server , for example our code is running in another pc, with the previous code we tipically get an WebException, with HTTP Status 401, because we are not in the domain or we are a user with another password.

In this case we must Impersonate the user:

svrMoss.Lists objProxy = new svrMoss.Lists();
NetworkCredential objNc = new NetworkCredential(“administrator”, “pwd”, “domain”);
objProxy.Credentials = objNc;
objProxy.PreAuthenticate = true;

PreAuthenticate = true tipically was not needed in my code ; in MSDN the definition is

“if PreAuthenticate is true and credentials are supplied, the WWW-authenticate header is sent with each request to that Uri; otherwise, the request uses standard authentication procedures.”

Advertisements
Categories: SharePoint
%d bloggers like this: