您的位置:首页 > 其它

After upgrading the ebPart Assembly "Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed .."

2009-04-23 18:07 441 查看
我们项目开发了一些webpart, 客户要求以后升级版本后,以前的webpart也应该能用。

我们试验发现,一旦assembly版本发生变化后,以前的webpart都会报这么一个错误:

Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.

Show Error Details
Hide Error Details

[UnsafeControlException: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.]
at Microsoft.SharePoint.ApplicationRuntime.SafeControls.GetTypeFromGuid(Guid guid)
at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CreateWebPartsFromRowSetData(Boolean onlyInitializeClosedWebParts)

后来经过调查,发现按照下列步骤可以解决这个问题。

1. 首先修改web.config中webpart对应的safecontrol配置部分,将版本修改到旧的版本号。

2. 在<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
节点处添加一个新的bindingRedirect项目。如下:

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

3. 此时你再访问你的webpart页面,这些webpart应该都已经可以正常访问了。

4. 最后是一个奇怪的现象,一旦你正常访问这些webpart后,你再撤销刚才那些对web.config的修改也没有什么问题了。不过个人认为还是不删除的好。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐