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

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

你可能感兴趣的:(assembly)