我有一個事件接收器(WebAdding和WebProvisioned),它適用於從網站集的根目錄創建的網站。但是,子網站(例如,在其他區域內創建的團隊網站)完全不會觸發代碼。Sharepoint 2010事件接收器不會觸發子網站
有沒有人有任何想法,爲什麼?
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
using System.Text;
namespace TestEventReceiver.EventReceiver1
{
/// <summary>
/// Web Events
/// </summary>
public class EventReceiver1 : SPWebEventReceiver
{
/// <summary>
/// A site is being provisioned.
/// </summary>
public override void WebAdding(SPWebEventProperties properties)
{
base.WebAdding(properties);
using (SPWeb web = properties.Web)
{
StringBuilder output = new StringBuilder();
output.AppendFormat("Web Adding");
output.AppendFormat("<br>Web title: {0}",web.Title);
SendMyEmail(web, "[email protected]", "Web Adding", output.ToString());
}
}
/// <summary>
/// A site was provisioned.
/// </summary>
public override void WebProvisioned(SPWebEventProperties properties)
{
base.WebProvisioned(properties);
using (SPWeb web = properties.Web)
{
StringBuilder output = new StringBuilder();
output.AppendFormat("Web Provisioned");
output.AppendFormat("<br>Web title: {0}", web.Title);
SendMyEmail(web, "[email protected]", "Web Provisioned", output.ToString());
}
}
private void SendMyEmail(SPWeb Web, String toAddress, String subject, String message)
{
bool appendHtmlTag = false;
bool htmlEncode = true;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPUtility.SendEmail(Web, appendHtmlTag, htmlEncode, toAddress, subject, message);
});
}
}
}
由於提前, 馬特
嗨,布賴恩 - 謝謝你的回覆。但是,事件接收器應該在WebAdding和WebProvisioned事件上都觸發,但不會觸發任何子站點。即使爲WebProvisioned enevt創建了一個新的事件接收器,它仍然不會觸發子網站。 – 2011-04-07 08:48:33
馬特,你能解釋「子網站(例如,在其他地區創建的團隊網站)」嗎?這些實際上是根級網站集下的網站集。 (他們是否有一個託管路徑(http:// servername/sites/sitecollectionName)。我認爲他們可能實際上是一個新網站集的根網站,並且這些事件不會在該級別激發。 – 2011-04-08 02:02:51