如何在Sharepoint母版页中包含动态信息?

发布于 2024-09-15 19:03:02 字数 550 浏览 5 评论 0原文

我们正在创建几个 (19) 个站点,将在 Sharepoint 2007 中托管,并希望使用 Google Analytics。第一点很简单,只需将 Google Analytics javascript 放入 Sharepoint 母版页中,一切都按预期工作。

然而,我们希望 19 个站点中的每一个都生成单独的统计数据,这是通过为每个站点设置不同的 ID 来完成的。我的第一个想法是将 id 存储在每个站点的 web.config 中,并更改母版页以读取 javascript:

<%= ConfigurationManager.AppSettings["google.analytics.key"]%> 

不幸的是,Sharepoint 不喜欢这样,并说:此文件中不允许使用代码块。

我的问题是:

有没有办法从 Sharepoint 母版页中的 web.config 读取 appSettings?或者

是否有更好的 Sharepoint 方式将特定于站点的信息放入母版页中?或者

我是否坚持为每个站点使用单独的母版页?

We are creating several (19) sites to be hosted in Sharepoint 2007 and want to use Google Analytics. The first bit was easy, simply putting the Google Analytics javascript in the Sharepoint master page and all worked as expected.

However, we want each of the 19 sites to generate seperate statistics and this is done by having a different id for each site. My first thought was to store the id in each site's web.config and change the master page to read this for the javascript:

<%= ConfigurationManager.AppSettings["google.analytics.key"]%> 

Unfortunately, Sharepoint doesn't like this and says: Code blocks are not allowed in this file.

My question is:

Is there a way to read appSettings from web.config in a Sharepoint master page? or

Is there a better, Sharepoint-way of getting site-specific information into a master page? or

Am I stuck with using seperate master pages for each of the sites?

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

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

发布评论

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

评论(2

梦归所梦 2024-09-22 19:03:02

您提出的建议非常不安全,因为它允许任何使用共享点设计器的贡献者将任何代码添加到母版页,这绝不是一个好主意。我建议在任何情况下都使用服务器控件,这将只需要几分钟的时间来开发,但之后会为您省去很多麻烦

What you proposed is extremely unsafe, as it allows any contributor using sharepoint designer to add any code to the master page, this is never a good idea. I would suggest using a server control in any case, this will take only a few minutes to develop but would save you a lot of headache afterwards

带刺的爱情 2024-09-22 19:03:02

默认情况下,SharePoint 不允许在母版页中包含代码,因此您需要将母版页标记为对代码安全。在你的 web.config 中你将有以下设置:

<SharePoint>
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" totalFileDependencies="50" AllowPageLevelTrace="false">
  <PageParserPaths>
  </PageParserPaths>
</SafeMode>

您需要将其更改为包括:

<PageParserPaths>
    <PageParserPath VirtualPath="/_layouts/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/>
</PageParserPaths>

这将告诉 SharePoint 允许母版页中的代码。您可以使用相同的想法来允许其他 SharePoint 位置中的代码。

另一种选择是使用代码隐藏,但根据您的问题,我假设您不想这样做。

SharePoint by default doesn't allow code in master pages, then you will need to mark the masterpages as being safe for code. In your web.config you will have the following setting:

<SharePoint>
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" totalFileDependencies="50" AllowPageLevelTrace="false">
  <PageParserPaths>
  </PageParserPaths>
</SafeMode>

You will need to change it to include:

<PageParserPaths>
    <PageParserPath VirtualPath="/_layouts/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/>
</PageParserPaths>

This will tell SharePoint to allow code in the masterpage. You can use the same idea to allow code in other SharePoint locations.

The other option is to use codebehind, but I'm assuming based on your questions that you don't want to do this.

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