问题描述
我想通过传递认证信息来实现自定义日志记录,如下参考链接显示在:
I want to implement a custom logging by passing authentication information, as shown in below reference links:
- http://blogs.msdn.com/b/cjohnson/archive/2011/05/03/authentication-with-sharepoint-online-and-the-client-side-object-model.aspx
- http://msdn.microsoft.com/en-us/library/hh147177(v=office.14).aspx
我用下面code,但它不会自动登录,而不是它只是弹出登录窗口中输入用户名和密码。我想通过传递凭据语法Pro自动登录。
I'm using below code but it does not automatically login instead it just popup the login window to enter username and password. I want to automatically log in by passing the credentials pro grammatically.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using System.Net;
using MSDN.Samples.ClaimsAuth;
namespace Sp_Ctx
{
class Program
{
[STAThread]
static void Main(string[] args)
{
//if (args.Length < 1) { Console.WriteLine("SP_Ctx <url>"); return; }
string targetSite = "https://mysite.sharepoint.com";//args[0];
using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext(targetSite))
{
if (ctx != null)
{
ctx.Credentials = new NetworkCredential("[email protected]", "password", "mysite.sharepoint.com");
ctx.Load(ctx.Web); // Query for Web
ctx.ExecuteQuery(); // Execute
Console.WriteLine(ctx.Web.Title);
}
}
Console.ReadLine();
}
}
}
更新:
我主持的 MS 365的SharePoint 2013网站,但我想用2010版的认证机制。
I've hosted a MS 365 sharepoint 2013 site but i want to use the version 2010 authentication mechanism.
推荐答案
试试这个:
ctx.Credentials = new NetworkCredential("guest", "password", "mysite.com.au");
域的凭据应该是你的来宾帐户,而不是SharePoint服务器的域。
The Domain in the credentials should be the domain of your guest account instead of sharepoint server name.
这篇关于SharePoint Foundation 2010的客户端对象模型验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!