症状
安装以下更新之一后,Microsoft SharePoint 中的某些幻像页面无法呈现:
-
SharePoint Enterprise Server 2016 安全更新说明:2020 年 9 月 8 日 (KB 4484506)
-
SharePoint Foundation 2013 安全更新说明:2020 年 9 月 8 日 (KB 4484525)
-
SharePoint Foundation 2010 安全更新说明:2020 年 9 月 8 日 (KB 4486667)
例如,Microsoft Identity Manager (MIM) 门户页面和通过 SharePoint 解决方案部署的某些自定义页面无法呈现。
此外,你还可能遇到一个或多个以下场景。
场景 1
被阻止的幻像页面显示以下错误消息之一:
-
此页面不允许使用属性“autoeventwireup”。
-
此页面不允许使用属性“enablesessionstate”。
-
该文件中不允许使用代码块。
-
此页面不允许使用事件处理程序“OnSelectedIndexChanged”。
注意 最后一条错误消息中的事件也可能是某个其他事件,例如“OnClick”。
场景 2
被阻止的幻像页面显示以下错误消息:
UnsafeControlException:无法显示或导入此页上的 Web 部件或 Web 窗体控件。找不到类型或未将其注册为安全类型。
场景 3
被阻止的幻像页面显示以下错误消息:
此页面上不允许使用引用的文件 '/_layouts/somedirectory/affectedusercontrol.ascx'。
原因
幻像页面存储在文件系统中。通过禁止服务器端脚本和不安全的控件,这些页面的安全级别得到了增强。如果满足以下条件,则可能会阻止幻像页面呈现:
-
幻像页面包含内联代码或服务器端脚本。
-
代码隐藏类型或 Web 部件类型未注册为安全类型。
场景 1 的解决方案
要解决此问题,请将具有 VirtualPath 属性的新 PageParserPath 元素添加到 Web.config 文件的 configuration/SharePoint/SafeMode/PageParserPaths 元素下。
例如,您可能会收到下面的错误消息:
“此页面不允许使用属性 'autoeventwireup'。”
在这种情况下,你可以添加一个 PageParserPath 元素,如下所示:
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="15" TotalFileDependencies="250" AllowPageLevelTrace="false">
<PageParserPaths>
<PageParserPath VirtualPath="/<relativepath>/page.aspx" CompilationMode="Always" AllowServerSideScript="true" AllowUnsafeControls="true"/>
</PageParserPaths>
</SafeMode>
如果必须解除阻止同一虚拟目录中的所有页面,则可以使用 PageParserPath 元素,如下所示:
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="15" TotalFileDependencies="250" AllowPageLevelTrace="false">
<PageParserPaths>
<PageParserPath VirtualPath="/<relativepath>/*" CompilationMode="Always" AllowServerSideScript="true" AllowUnsafeControls="true" IncludeSubFolders="True"/>
</PageParserPaths>
</SafeMode>
-
VirtualPath 是被阻止页面的路径。
-
VirtualPath 必须引用已被幻像且不能被任何用户取消幻像的页面,或包含此类页面的目录。
-
VirtualPath 必须引用一个页面,该页面未引用另一个页面或可以被取消幻像的母版页面,或者不包含此类页面或母版页面的目录。
-
DirectFileDependencies 指示允许的直接文件依赖项的数量。如果收到诸如“允许的直接文件依赖项的数量超过限制”之类的错误消息,请更改此值。
场景 2 的解决方案
要解决此问题,请针对给定的类型、命名空间和程序集强名称,将一个新的 SafeControls 元素添加到 Web.config 文件的 configuration/SharePoint/SafeControls 元素下,如 SafeControls 元素(解决方案)中所述。然后,将 Safe 属性设置为 TRUE。
有关 SafeControls 元素中属性值格式的详细信息,请参阅如何:将控件标记为安全控件的“在包设计器中标记安全控件”部分的步骤 12 中的表。
场景 3 的解决方案
要解决此问题,请将使用 Src 属性的新 SafeControls 元素添加到 Web.config 文件的 configuration/SharePoint/SafeControls 元素下。
例如,你会收到以下错误消息:
“此页面上不允许使用引用的文件 '/_layouts/somedirectory/affectedusercontrol.ascx'。”
在这种情况下,你可以添加 SafeControls 元素,如以下示例所示:
< SafeControls>
<SafeControl Src="~/_layouts/somedirectory/*" IncludeSubFolders="True" Safe="True" AllowRemoteDesigner="True" SafeAgainstScript="True" />
</SafeControls>
< SafeControls> <SafeControl Src="~/_layouts/somedirectory/*" IncludeSubFolders="True" Safe="True" /> </SafeControls>