如何将 SharePoint 2007 功能挂接到网站的 Application_Start 中?

发布于 2024-07-06 03:27:35 字数 143 浏览 15 评论 0原文

我想知道在开发功能时是否有一种好方法可以挂钩 SharePoint 2007 网站的 Application_Start? 我知道我可以直接编辑站点根目录中的 Global.asax 文件,但是有没有办法做到这一点,以便它与该功能一起部署?

谢谢!

I was wondering if there is a good way to hook into the Application_Start of a SharePoint 2007 site when developing a feature? I know I can directly edit the Global.asax file in the site root, but is there a way to do this so that it gets deployed with the feature?

Thanks!

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

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

发布评论

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

评论(2

我也只是我 2024-07-13 03:27:35

这其实是可以的,但是不涉及Global.asax文件。

Microsoft 的许多示例都演示了通过 Global.asax 连接代码,但这并不是 SharePoint 的最佳实践方法。 理想情况下,您的代码应打包为功能并通过 WSP 进行部署(正如您所知)。

关键在于将相关代码实现为 HttpModule(即实现 IHttpModule 接口的类型)并将其连接到为 SharePoint 应用程序提供服务的 ASP.NET 管道中。 粗略地说,步骤如下:

  1. 创建一个实现 IHttpModule 接口的类。
  2. 在 HttpModule 中实现 Init 方法; 这是在 HttpApplication(在本例中为 SPHttpApplication)设置时调用的,它使您有机会执行处理、为其他管道事件连接事件委托等。
  3. 创建一个 SPFeatureReceiver,它将添加和删除您的 HttpModule分别来自激活和停用时的目标 web.config 文件。 这是使用 SPWebConfigModification 类型来更新来执行的。 目标 web.config 文件中的节点。
  4. 将所有内容打包为功能并通过 WSP 进行部署。

有关 HttpModule 开发的详细信息,请参阅 http://msdn.microsoft.com/ en-us/library/ms227673.aspx。 有关 SPWebConfigModification 类型的其他详细信息,请参阅 http: //msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.aspx

结果:一个可以处理应用程序启动并可通过功能部署的类。 无需手动破解文件。

我已经在许多场景中成功地使用了它——最近的一个自定义缓存提供程序 (IVaryByCustomHandler) 需要在启动时向 SPHttpApplication 注册自己以进行回调。

虽然你的问题有点老了,但我希望这会有所帮助!

This is actually possible, but it doesn't involve the Global.asax file.

Many of Microsoft's examples demonstrate wiring code in via the Global.asax, but this is not a best-practices approach when it comes to SharePoint. Ideally, your code should get packaged as a Feature and deployed via WSP (as you already know).

The key lies in implementing the code in question as an HttpModule (i.e., a type that implements the IHttpModule interface) and wiring it into the ASP.NET pipeline servicing your SharePoint application. Roughly speaking, these are the steps:

  1. Create a class that implements the IHttpModule interface.
  2. Implement the Init method in your HttpModule; this is called when the HttpApplication (in this case, the SPHttpApplication) is setup, and it gives you an opportunity to carry out processing, wire-up event delegates for other pipeline events, etc.
  3. Create an SPFeatureReceiver that will add and remove your HttpModule from target web.config files on activation and deactivation, respectively. This is carried out using the SPWebConfigModification type to update the <httpModules> node in target web.config files.
  4. Package all as a Feature and deploy via WSP.

For more information on HttpModule development, see http://msdn.microsoft.com/en-us/library/ms227673.aspx. For some additional detail on the SPWebConfigModification type, see http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.aspx.

Result: a class that can handle application startup and is deployable via Feature. No manual file hacking required.

I've successfully used this in a number of scenarios -- most recently with a custom caching provider (IVaryByCustomHandler) that needed to register itself for callbacks with the SPHttpApplication when it started.

Though your question is a bit older, I hope this helps!

雄赳赳气昂昂 2024-07-13 03:27:35

我的直觉是这是不可能的。 Application_Start 在 asp.net 引擎启动时由运行时调用,因此除了修改 Global.asax 之外,很可能没有任何方法可以挂钩处理程序 - 例如,挂钩必须是声明性的和持久性的,因为它必须在应用程序停止/卸载后继续存在。 因此,如果您必须写入 global.asax,我想您可以编写一个 Feature EventReceiver 来执行修改。

除此之外,您能详细说明原因吗? 也许还有其他的攻击角度。 即时修改 global.asax 的想法让我感到不舒服。 那可不太好。

奥辛

My gut feeling on this is that it won't be possible. Application_Start is called by the runtime as the asp.net engine is starting up, so there most likely can't be any way to hook the handler outside of modifying the Global.asax - e.g. the hook must be declarative and persistent as it has to survive the application stopping/unloading. So, if you have to write to the global.asax, I guess you could write a Feature EventReceiver to perform the modification.

That aside, can you give more details on the why? Perhaps there are other angles of attack. The idea of modifying the global.asax on the fly makes me feel ill. That can't be good.

Oisin

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