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

      我们项目开发了一些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的修改也没有什么问题了。不过个人认为还是不删除的好。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值