如何将SharePoint 2007功能挂钩到网站的Application_Start中? [英] How can you hook a SharePoint 2007 feature into the Application_Start of a site?

查看:106
本文介绍了如何将SharePoint 2007功能挂钩到网站的Application_Start中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道开发功能时是否有一种很好的方法可以挂接到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?

谢谢!

推荐答案

这实际上是可行的,但不涉及Global.asax文件.

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

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

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).

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

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

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

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.

结果:一个可以处理应用程序启动并且可以通过Feature进行部署的类.无需手动文件黑客攻击.

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

我已经在许多情况下成功使用了此方法-最近在一个自定义的缓存提供程序(IVaryByCustomHandler)中使用了它,它需要在SPHttpApplication启动时为回调进行注册.

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!

这篇关于如何将SharePoint 2007功能挂钩到网站的Application_Start中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆