【问题标题】:SP 2007 - Webpart cannot be displayedSP 2007 - Webpart 无法显示
【发布时间】:2011-12-15 03:24:07
【问题描述】:

错误:“无法显示或导入此页面上的 Web 部件。找不到类型或未将其注册为安全”

试图在源代码中查找此错误的详细信息,但不太确定问题的确切位置。

请参阅 This Thread 了解以前执行的修复。

有什么好的起点吗?

DLL: TCBOE.ChartPart.dll

命名空间: TCBOE.Chartpart

FeatureReceiver.vb

Private Shared Sub AddOrRemoveChartHandlerToWebConfig(ByVal web As SPWebApplication, ByVal remove As Boolean)
    Dim asm As String = String.Format(CultureInfo.InvariantCulture, _
      "System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version={0}, Culture=neutral, PublicKeyToken={1}", _
      New Object() {"3.5.0.0", "31bf3856ad364e35"})
    Dim modif As New SPWebConfigModification("add[@path='ChartImg.axd']", _
      "configuration/system.web/httpHandlers")
    modif.Owner = "TCBOE.ChartPart"
    modif.Sequence = 0
    modif.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode

    modif.Value = String.Format(CultureInfo.InvariantCulture, _
      "<add verb=""{0}"" path=""{1}"" type=""{2}"" validate=""{3}"" />", _
      New Object() {"GET,HEAD,POST", "ChartImg.axd", asm, "false"})
    If (remove) Then
        web.WebConfigModifications.Remove(modif)
    Else
        web.WebConfigModifications.Add(modif)
    End If

End Sub
Private Shared Sub AddOrRemoveChartSettingsToWebConfig(ByVal web As SPWebApplication, ByVal remove As Boolean)
    Dim appSettings As New SPWebConfigModification("appSettings", "configuration")
    appSettings.Owner = "TCBOE.ChartPart"
    appSettings.Sequence = 0
    web.WebConfigModifications.Add(appSettings)

    Dim keyVal As String = String.Format(CultureInfo.InvariantCulture, _
     "storage={0};timeout={1};", _
     New Object() {"memory", "20"})
    Dim modif As New SPWebConfigModification("add[@key='ChartImageHandler']", "configuration/appSettings")
    modif.Owner = "TCBOE.ChartPart"
    modif.Sequence = 1
    modif.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode

    modif.Value = String.Format(CultureInfo.InvariantCulture, _
      "<add key=""{0}"" value=""{1}"" />", _
      New Object() {"ChartImageHandler", keyVal})
    If remove Then
        web.WebConfigModifications.Remove(modif)
    Else
        web.WebConfigModifications.Add(modif)
    End If
End Sub
<SharePointPermission(System.Security.Permissions.SecurityAction.Demand, ObjectModel:=True)> _
Public Overrides Sub FeatureActivated(ByVal properties As Microsoft.SharePoint.SPFeatureReceiverProperties)
    Dim site As SPSite = TryCast(properties.Feature.Parent, SPSite)
    Dim web As SPWebApplication = site.WebApplication
    AddOrRemoveChartSettingsToWebConfig(web, False)
    AddOrRemoveChartHandlerToWebConfig(web, False)
    web.Farm.Services.GetValue(Of SPWebService)().ApplyWebConfigModifications()
    web.Update()
End Sub
<SharePointPermission(System.Security.Permissions.SecurityAction.Demand, ObjectModel:=True)> _
Public Overrides Sub FeatureDeactivating(ByVal properties As Microsoft.SharePoint.SPFeatureReceiverProperties)
    Dim site As SPSite = TryCast(properties.Feature.Parent, SPSite)
    Dim web As SPWebApplication = site.WebApplication
    AddOrRemoveChartSettingsToWebConfig(web, True)
    AddOrRemoveChartHandlerToWebConfig(web, True)
    web.Farm.Services.GetValue(Of SPWebService)().ApplyWebConfigModifications()
    web.Update()
End Sub

添加时间:2011 年 10 月 26 日上午 11:36

清单.xml

(由 WSPBuilder 创建)

<?xml version="1.0"?>
<!-- Solution created by WSPBuilder. 10/26/2011 8:19:40 AM  -->
<Solution SolutionId="ee03c5c2-c9bd-4cfe-ac16-225f8e28072b" xmlns="http://schemas.microsoft.com/sharepoint/">
  <Assemblies>
    <Assembly Location="cablib.dll" DeploymentTarget="GlobalAssemblyCache" />
    <Assembly Location="TCBOE.ChartPart.dll" DeploymentTarget="GlobalAssemblyCache">
      <SafeControls>
        <SafeControl Assembly="TCBOE.ChartPart, Version=3.5.1.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" Namespace="TCBOE.ChartPart" TypeName="*" Safe="True" />
      </SafeControls>
    </Assembly>
  </Assemblies>
  <TemplateFiles>
    <TemplateFile Location="IMAGES\ChartPartWP\oscillator_16.gif" />
    <TemplateFile Location="IMAGES\ChartPartWP\oscillator_32.gif" />
  </TemplateFiles>
  <FeatureManifests>
    <FeatureManifest Location="ChartPartWP\feature.xml" />
  </FeatureManifests>
</Solution>

在任何情况下,CAS 策略会限制本地计算机用户帐户(用于运行服务)会导致这种行为?

2011 年 11 月 3 日编辑:

好的,终于安装了“Great Practices”,它稳定且有效。获得了我正在自定义的原始控件以加载和正常工作。

去“安装”我编辑的控件并在尝试部署解决方案时收到此错误响应:

Feature '47d62f5e-b0e0-4f93-bcd1-081ca794527c' could not be installed because the loading of event receiver assembly "TCBOE.ChartPart, Verstion=3.5.1.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" failed: System.IO.FileNotFoundException: Could not load file or assembly 'TCBOE.ChartPart, Culture=neutral, PublicKeyToken=9f4da00116c38ec5' or one of its dependencies. The system cannot find the file specified. 
File name: 'TCBOE.ChartPart, Culture=neutral, PublicKeyToken=9f4da00116c38ec5' 
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) 
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) 
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) 
   at System.Reflection.Assembly.Load(String assemblyString) 
   at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject() 

WRN: Assembly binding logging is turned OFF. 
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. 
Note: There is some performance penalty associated with assembly bind failure logging. 
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

【问题讨论】:

  • 添加了用于控件本身的功能接收器代码。
  • 在尝试部署解决方案时添加了来自 CA 的错误响应
  • 发现问题与 Sharepoint 服务器的安装不当有关。用显微镜卸载并按照安装步骤操作,现在一切正常。

标签: sharepoint sharepoint-2007 web-parts


【解决方案1】:

Web 部件应在 web.config 的 SafeControls 中注册。这很简单。试试下面的链接:

http://msdn.microsoft.com/en-us/library/ms581321(v=office.12).aspx

【讨论】:

  • 这可以像通过 FeatureReceiver 一样自动完成吗?
  • @GoldBishop 我不会在 FeatureReceiver 中执行此操作,而是在 manifest.xml 文件中执行此操作。看看andrewconnell.com/blog/articles/…。您还可以使用 WSPBuilder 动态生成清单。 wspbuilder.codeplex.com 。我认为首先要以“硬”的方式来做这件事很重要,但要充分了解幕后发生的一切。
  • 我完全赞成先长期这样做,所以当 SHORT 版本不起作用时,我就有了故障保险。问题是我下载了原始控件的 WSP 并尝试实现它,我得到了相同的结果。有没有办法干净地删除与视线相关的所有组件?我认为我有过度实现溢出,并且符号在应该删除时没有被删除。
  • 好的,不太清楚为什么会发生此错误,但在事件查看器中发现:初始化安全控件时出错 - 程序集:TCBOE.ChartPart,版本=3.5.1.0,文化=中性, PublicKeyToken=9f4da00116c38ec5 类型名称:TCBOE.ChartPart.ChartPartWP 错误:无法加载文件或程序集“System.Web.DataVisualization,版本=3.5.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。系统找不到指定的文件。
  • 为 3.5 安装了 MSChartControls,现在我从 .webpart 元素 部分获取 ImportErrorMessage。猜猜这会导致我找出我在其中预设的哪些默认值不适用于类中的数据类型设置。
【解决方案2】:

您是否使用用户控件来呈现 Web 部件?如果是这样,请将其放在 UserControl 的顶部:

<%@ Assembly Name="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>

如果您没有使用 UserControl,只需修改您的代码以将该行添加到标签内的 web.config 中:

<add assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

我在另一个线程中告诉过你,你正在以超硬模式的方式尝试手动摆弄这些东西。如果您使用的是 SmartPart 或 VSeWSS 1.3,您将不会经历所有这些。

【讨论】:

  • 是的,但您假设我是从页面的代码端执行此操作的。我正在开发一个 webpart,它将在激活时自动将此信息放入 web.config 中,或者在停用时将其自身删除。一切都被陈述为好像我会是这样做的人。我不是最终将部署/使用此控件的人。所以我试图让它尽可能地对管理员友好。而且我只使用 DataVisualization 命名空间的各个方面来构建然后渲染图形。
  • 这个称为 Web 部件的可重复使用的可重新部署的神奇奇迹在您之前已经完成了十亿次,而人类从未见过这些“无法解释”的日常需求,例如使用 BCL 中未注册的 dll,因此良好做法不会'不适用,但我只是假设。
  • 我并不幻想我遇到的问题无论如何都是原创的......它更多地理解如果“这个”然后“那个”否则“做另一个”,如果所有其他失败“删除.,格式C:,重新安装” :) 说真的,我会从不同的角度问同样的问题,所以你必须耐心等待。我对 Web 开发并不陌生,只是 SharePoint 部署。如果这是一个 ASP.Net 页面,我不会遇到这些问题,但由于我使用的是 SharePoint 库框架,因此我处于个人未知领域。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-17
  • 1970-01-01
  • 2011-03-06
  • 2011-05-12
  • 2011-06-13
  • 2010-10-12
相关资源
最近更新 更多