Asp.net SharePoint基金会2010客户端对象模型认证
我想通过传递身份验证信息来实现自定义日志记录,如以下参考链接所示:Asp.net SharePoint基金会2010客户端对象模型认证,asp.net,sharepoint,office365,sharepoint-clientobject,Asp.net,Sharepoint,Office365,Sharepoint Clientobject,我想通过传递身份验证信息来实现自定义日志记录,如以下参考链接所示: 我使用下面的代码,但它不会自动登录,而只是弹出登录窗口输入用户名和密码。我想通过按语法传递凭据自动登录 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint.Client; using System.Net; using MSDN.Samples.Cl
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("guest@mysite.com.au", "password", "mysite.sharepoint.com");
ctx.Load(ctx.Web); // Query for Web
ctx.ExecuteQuery(); // Execute
Console.WriteLine(ctx.Web.Title);
}
}
Console.ReadLine();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用Microsoft.SharePoint.Client;
Net系统;
使用MSDN.Samples.ClaimsAuth;
名称空间Sp_Ctx
{
班级计划
{
[状态线程]
静态void Main(字符串[]参数)
{
//if(args.Length<1){Console.WriteLine(“SP_Ctx”);return;}
字符串targetSite=”https://mysite.sharepoint.com“;//参数[0];
使用(ClientContext ctx=ClaimClientContext.GetAuthenticatedContext(targetSite))
{
如果(ctx!=null)
{
ctx.Credentials=新的网络凭据(“guest@mysite.com.au“、”密码“、”mysite.sharepoint.com”);
Load(ctx.Web);//查询Web
ctx.ExecuteQuery();//执行
Console.WriteLine(ctx.Web.Title);
}
}
Console.ReadLine();
}
}
}
更新:
我托管了一个MS 365 sharepoint 2013网站,但我想使用2010版身份验证机制 您正在使用的MSDN示例项目将只允许通过弹出窗口进行基于声明的身份验证。为了通过编程实现这一点,我使用了另一个助手库wictorwilén's。然后可以使用他的MsOnlineClaimsHelper类进行身份验证。以下是直接取自Wictor博客的示例代码:
MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper(url, username, password);
using (ClientContext context = new ClientContext(url)) {
context.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
context.Load(context.Web);
context.ExecuteQuery();
Console.WriteLine("Name of the web is: " + context.Web.Title);
}
这是我六个月前为一个项目所做的。但是,我很想知道微软是否提供了新的最佳实践或其他东西。试试这个:
ctx.Credentials = new NetworkCredential("guest", "password", "mysite.com.au");
凭据中的域应为来宾帐户的域,而不是sharepoint服务器名称。请查看此URL。请让我知道这是否有用这是我尝试的第一个例子:)