无法使用远程事件接收器在主机Web列表上创建列表项 [英] Can't create list item on host web list with remote event receiver
本文介绍了无法使用远程事件接收器在主机Web列表上创建列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
我正在使用此代码创建日历项目.请注意,此功能过去一直有效,但今天却无效.我不知道为什么,我无法调试它,因为我使用的是仅应用程序"权限.
I'm using this code to create a calendar item. Please note that this used to work but today it doesn't. I don't know why and i can't debug it because i'm using app only permissions.
任何想法为什么它不起作用?
Any ideas why it doesn't work?
public void createCalendarItem(DateTime startDate,DateTime endDate, Double workDaysRequested, String requesterName)
{
string webUrl = "myurlhere";
//using (ClientContext clientContextWeb = TokenHelper.CreateRemoteEventReceiverClientContext(propertiesFunction))
//{
// clientContextWeb.Load(clientContextWeb.Web);
// clientContextWeb.ExecuteQuery();
// webUrl = clientContextWeb.Web.Url;
//}
//string webUrl = properties.ItemEventProperties.WebUrl;
Uri webUri = new Uri(webUrl);
string realm = TokenHelper.GetRealmFromTargetUrl(webUri);
string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, webUri.Authority, realm).AccessToken;
var clientContextTest = TokenHelper.GetClientContextWithAccessToken(webUrl, accessToken);
using (var clientContextAdmin = clientContextTest)
{
if (clientContextAdmin != null)
{
List calendarList = clientContextAdmin.Web.Lists.GetByTitle("LeaveCalendar");
clientContextAdmin.Load(calendarList);
clientContextAdmin.ExecuteQuery();
ListItemCreationInformation calendaritemCreationInfo = new ListItemCreationInformation();
ListItem calendarItem = calendarList.AddItem(calendaritemCreationInfo);
calendarItem["Title"] = "Leave Request for " + requesterName + " for " + Convert.ToString(workDaysRequested) + " day(s)";
calendarItem["EventDate"] = startDate;
calendarItem["EndDate"] = endDate;
calendarItem.Update();
clientContextAdmin.ExecuteQuery();
}
}
}
推荐答案
您好,
由于您的解决方案以前可以正常工作,因此不应进行编码,因此建议您使用提琴手来解决此问题.
安装 提琴手.
Install Fiddler.
更新网络配置. >
<system.net>
<defaultProxy>
<proxy usesystemdefault="False" bypassonlocal="False" proxyaddress="http://127.0.0.1:8888" />
</defaultProxy>
</system.net>
您可以在下面的链接中查看详细信息.
You could check below link for details.
Lee
这篇关于无法使用远程事件接收器在主机Web列表上创建列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文