开发者

How do I supply credentials to execute a query on a server that's part of another domain?

I am doing work for a client that has a server on his domain. My workstation is on my own domain. I typically VPN into the client network using my client domain username and password. The problem with the below query is that I get a 401 Unauthorized access error when I execute the query, presumably because the wrong credentials are being sent.

The client has suggested supplying my client domain credentials, perhaps wrapped in a #if DEBUG so that the code will work properly in development environments.

How do I supply credentials? The following code will be present in an ASP MVC 2 project.

        ClientContext clientContext = new ClientContext(URL);
        List list = clientContext.Web.Lists.GetByTitle("My Documents");

        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml = XML;
        ListItemCollection listItems = list.开发者_运维知识库GetItems(camlQuery);
        clientContext.Load(
             listItems,
             items => items.Include(item => item["FileRef"]));

        clientContext.ExecuteQuery();

I prefer to do this programatically


Is this all I need to do:

        System.Net.NetworkCredential cred = new System.Net.NetworkCredential("myname", "mypassword"); 
    ClientContext clientContext = new ClientContext(URL);

    clientContext.Credentials = cred;

I am still not getting success, but perhaps there are some other issues here.


You could configure the Application Pool credential on the IIS, this way the "user" running the application has permission to access the other server.


If the client account is already a valid user of the sharepoint site you just need to use the default credentials before downloading, like so..

WebClient Client=new WebClient();
Client.UseDefaultCredentials=true;
Client.DownloadFile(url, destination);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜