我有一个SharePoint 2010事件接收器,用于侦听SharePoint列表上的添加/更新/删除事件。当事件发生时,用C#编写的事件接收器需要将这些事件传递给Java程序。我的代码发布在下面。我可以很好地部署接收器,它的工作原理。我得到了我需要的所有SharePoint事件。现在我的问题是将这些事件传递给Java。每次尝试打开套接字或将SharePoint事件写入文件时,我都会收到安全性异常。例如,查看下面发布的ItemDeleting方法,每次从SharePoint列表中删除项时都会触发该方法。当我尝试打开Java套接字时,我得到System.Net.DnsPermission异常。如果我不打开套接字并尝试写入文件,我会收到System.Security.Permissions.FileIOPermission异常。
我环顾了论坛,我尝试了几件事来解决问题。首先,我在SharePoint的web.xml中设置trust level =“Full”。然后我设置程序集的DeploymentTarget =“GlobalAssemblyCache”。这没有用。我还可以做些什么?提前感谢您的回复。
我的活动接收者代码:
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
using System.Net.Sockets;
using System.IO;
namespace EventReceiverTest
{
public class EventReceiver1 : SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
}
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
}
public override void ItemDeleting(SPItemEventProperties properties)
{
//can't open a socket connection.Request for the permission of type 'System.Net.DnsPermission,... failed
TcpClient tc = new TcpClient("192.168.xxx.xxx", xxx);
Console.WriteLine("Server invoked");
NetworkStream ns = tc.GetStream();
StreamWriter sw = new StreamWriter(ns);
sw.WriteLine("item deleted");
sw.Flush();
StreamReader sr = new StreamReader(ns);
Console.WriteLine(sr.ReadLine());
//can't write to file. Request for the permission of type 'System.Security.Permissions.FileIOPermission,...failed
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\logs\\test.txt");
file.WriteLine("item deleted " + properties.ListItem);
//can't output anything to a console
Console.Out.WriteLine("deleting an item ");
base.ItemDeleting(properties);
//but this part works
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Deleting items from " + properties.RelativeWebUrl + " is not supported.";
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
<Properties>
<Property Key="GloballyAvailable" Value="true" />
</Properties>
</Feature>
<?xml version="1.0" encoding="utf-8"?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/">
<Assemblies>
<Assembly Location="EventReceiver3.dll" DeploymentTarget="GlobalAssemblyCache" />
</Assemblies>
<FeatureManifests>
<FeatureManifest Location="EventReceiver3_Feature1\Feature.xml" />
</FeatureManifests>
</Solution>
答案 0 :(得分:0)
您需要FullTrust并运行访问“SharePoint:System”帐户下的系统资源(如文件)的代码。