在 SharePoint 网站中存储网站级全局变量的正确方法是什么?

发布于 2024-09-05 17:36:21 字数 823 浏览 6 评论 0原文

让我对 SharePoint2007 感到抓狂的一件事是,它显然无法拥有专门应用于网站或网站集本身(而不是内容)的可定义设置。我的意思是,您有一些预定义的设置,例如站点徽标、站点名称和各种其他内容,但似乎没有任何地方可以添加新类型的设置。

我正在开发的应用程序需要能够创建多种“项目网站集”,这些网站集都遵循基本模板,但具有专门应用于该网站集和单独网站集的某些附加设置。除了标准站点名称之外,我们还需要定义项目编号、项目名称和客户名称。考虑到一些客户的要求,我们还必须拥有可配置的设置来改变某些工作流程的工作方式,例如文件是否用字母或数字标记。

我们当前的解决方案(我对此犹豫不决)是在 SharePoint 服务器上存储 XML 文件。该文件包含每个网站集的一个节点,由根网站的 URL 标识。节点内部包含需要为该网站集定义的所有元素。当我们需要它们时,我们每次都必须访问 XML 文件(该文件始终需要 SPSecurity.RunWithElevatedPrivileges 才能访问服务器上的文件)以加载它并检索数据。有很多自动化流程必须执行此操作,当我们到达数百个站点,其中有数千个文件运行数万个工作流程,所有站点都想访问该文件时,我对这种方法的稳定性感到犹豫。也许这些担心是毫无根据的,但我宁愿担心,也不愿冒几年内一切都崩溃的风险。

我正在研究 SPWeb 对象并找到 AllProperties 哈希表。它看起来像是那种可能有效的东西,但我不知道修改它有多安全。我通读了 MSDN 和 WSS SDK,但没有发现任何关于向 AllProperties 添加全新属性的说明。使用 AllProperties 来做这种事安全吗?或者我还缺少另一个功能,它可以处理网站集或网站范围内的全局变量的概念?

One thing that has driven me nuts about SharePoint2007 is the apparent inability to have defineable settings that apply specifically to a site or site collection itself, and not the content. I mean, you have some pre-defined settings like the Site Logo, the Site Name, and various other things, but there doesn't appear to be anywhere to add new kinds of settings.

The application I am working on needs to be able to create multiple kinds of "project site collections" that all follow a basic template, but have certain additional settings that apply specifically to that site collection and that one alone. In addition to the standard site name we also need to define the Project Number, the Project Name, and the Client Name. And given the requests of some of our clients, we also reach a point where we have to have configurable settings that alter how some of the workflows work, like whether files are marked with Letters or Numbers.

Our current solution, which I'm hesitant about, has been to store an XML file on the SharePoint server. This file contains one node for each site collection, identified by the URL of the root site. Inside the node are all of the elements that need to be defined for that site collection. When we need them, we have to access the XML file (which will always require SPSecurity.RunWithElevatedPrivileges to access files right on the server) every time to load it and retrieve the data. There are a lot of automated processes which will have to do this, and I'm hesitant about the stability of this method when we reach hundreds of sites with thousands of files running tens of thousands of workflows, all wanting to access this file. Maybe they're unfounded worries, but I'd rather worry than risk everything breaking in a couple years.

I was looking into the SPWeb object and found the AllProperties hashtable. It looks like just the kind of thing which might work, but I don't know how safe it is to be modifying this. I read through both MSDN and the WSS SDK but found nothing that clarified on adding completely new properties into AllProperties. Is it safe to use AllProperties for this kind of thing? Or is there yet another feature that I am missing, which could handle the concept of global variables at the site collection or site scope?

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

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

发布评论

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

评论(3

甚是思念 2024-09-12 17:36:21

建议的方法是通过 SPFarm、SPWeb.RootWeb(用于网站集)、SPWeb、SPList 等(取决于您需要的范围)的 .Properties 使用 PropertyBag(键/值对)。

MSDN - 管理 SharePoint 应用程序的自定义配置选项

有一个可用于生产的代码,作为

MSDN - SharePoint 指导库

请参阅分层配置管理器

这使您能够以编程方式读取/写入这些值。如果您想在不使用指导库的情况下执行此操作,那么您可以使用类似以下代码的内容。

SPWeb web = SPContext.Current.Web;
if (web.Properties.ContainsKey("MyProperty"))
   string myProperty = web.Properties["MyProperty"];

如果您希望 UI 允许管理员轻松设置值,请使用 SharePoint设计器(urghhhh!)或类似SharePoint 属性包设置

The recommended way to do this is to use PropertyBag (key/value pairs) through the .Properties of SPFarm, SPWeb.RootWeb (for site collections), SPWeb, SPList etc (depending upon the scope that you need).

MSDN - Managing Custom Configuration Options for a SharePoint Application

There is a production ready code available as part of the

MSDN - The SharePoint Guidance Library

See Hierarchical configuration manager

This gives you programmatic access to read/write these values. If you want to do this without using the guidance library then you would use something like the following code.

SPWeb web = SPContext.Current.Web;
if (web.Properties.ContainsKey("MyProperty"))
   string myProperty = web.Properties["MyProperty"];

If you want a UI to allow admins to easily set the values then use either SharePoint Designer (urghhhh!) or something like SharePoint Property Bag Settings

听你说爱我 2024-09-12 17:36:21

propertybag 可用于存储键/值类型属性。我认为这就是为了你的目的。

就我个人而言,我更需要跨网站集属性(例如数据库连接字符串),并且我使用 this存储那些。

The propertybag can be used to store key/value type properties. I think it is meant for what your purposes seem to be.

Personally I have more need for cross-site collection properties (such as db connection strings) and I use this for storing those.

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