Sharepoint 2010 事件接收器未触发子站点

发布于 2024-10-30 02:57:47 字数 2166 浏览 2 评论 0原文

我有一个事件接收器(WebAdding 和 WebProvisioned),它适用于从网站集的根目录创建的网站。但是,子站点(例如,在其他区域内创建的团队站点)根本不会触发代码。

有人知道为什么吗?

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);
      });

    }

  }
}

提前致谢, 马特

I have an event receiver (WebAdding and WebProvisioned) which works just fine for sites created off the root of the site collection. However, subsites (for example, teamsites created within other areas) do not trigger the code at all.

Does anyone have any idea as to why?

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);
      });

    }

  }
}

Thanks in advance,
Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

东走西顾 2024-11-06 02:57:47

我认为你不应该使用 'Using' 。
您获得的 SPWeb 对象引用来自传递给 WebAdding 方法的properties.Web。因此你会遇到问题。

I think you should not be using 'Using' .
The SPWeb object reference you get is from properties.Web which is being passed to the WebAdding method. You will run into issues because of this.

泅人 2024-11-06 02:57:47

查看您的事件接收器是如何配置的 - 可能需要将范围更改为站点而不是 Web。也许你可以在这里发帖,以便我们看看。

Have a look at how your event receiver is provisioned - it may be the scope needs to be changed to Site rather than Web. Perhaps you could post here so we can see.

谜兔 2024-11-06 02:57:47

在我的网站上我也遇到了同样的问题。仍在弄清楚 xml 文件,但在接收器的 Elements.xml 文件中,每个接收器都有相同的序列号。一旦我将它们在 Elements.xml 文件中设置为唯一,WebProvisioned 事件就开始触发。不知道这是否与您遇到的问题相同。

On my site I had the same issue. Still figuring out the xml files, but in my Elements.xml file for the Receivers, each receiver had the same sequence number. Once I made them unique within the Elements.xml file, the WebProvisioned event started firing. Don't know if this is the same issue you were having.

江湖正好 2024-11-06 02:57:47

此代码显示 WebAdding 事件,并且该事件发生在父 Web 上。

http://msdn.microsoft.com/en-us /library/microsoft.sharepoint.spwebeventreceiver.webadding.aspx

This code is showing the WebAdding event and that event is occurring on the parent Web.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spwebeventreceiver.webadding.aspx

心作怪 2024-11-06 02:57:47

尝试更改接收器的范围(在 Elements.xml 文件中添加属性)。另外,请确保在子网站的网站功能中激活了事件接收器的功能。

Try to change scope of your receiver (in Elements.xml file add attribute ). Also, make sure that the feature of your Event receiver is activated in you site features in the subsite.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文