【问题标题】:SPSite constructor problem "Operation aborted"SPSite 构造函数问题“操作中止”
【发布时间】:2010-11-18 15:37:36
【问题描述】:

警告:我是一名 asp.net 开发人员,在 SharePoint 中迈出了第一步。

所以,我正在编写一个控制台应用程序,该应用程序连接到同一台计算机上的 SharePoint Server 2007 站点,但在调用 SPSite() 构造函数期间似乎出现了问题。这是简化的代码:

using (SPSite siteCollection = new SPSite("http://server/AwesomeSite"))
{

  //when i set a breakpoint on this line and inspect the siteCollection object, 
  //most of it's properties (for example siteCollection.AllWebs.Names) throw an 
  //exception, which leads me to the conclusion that something went wrong during 
  //the constructor above.

  SPWebCollection site = siteCollection.AllWebs;
  SPWeb web = site[""];
  SPList list = web.Lists["AwesomeList"]; //exception occurs here
}

SPException 文本:

操作中止(HRESULT 异常:0x80004004 (E_ABORT))

我听从了Sharepoint SPSite 的建议并检查了:

  1. 用户是服务器场管理员。
  2. 用户对内容数据库具有读取和写入权限。
  3. 用户是网站集管理员。
  4. 用户有权访问 Windows SharePoint Services 站点或代码迭代的 SharePoint Server 2007 站点。

而且它们都是正确的。还有什么可能导致这种情况发生?

【问题讨论】:

    标签: sharepoint sharepoint-2007


    【解决方案1】:

    根据我的经验,SPSite() 构造函数高度依赖于您网站的Alternate Access Mappings configuration。确保您在构造函数中使用的 URL 出现在映射列表中(例如,http 与 https、机器与 FQDN)。

    【讨论】:

      【解决方案2】:

      您需要获取更多调试信息。

      使用 Visual Studio

      尝试将调试器设置为中断所有异常。转至 DebugExceptions 并勾选 Common Language Runtime Exceptions。然后转到工具选项调试并取消勾选仅启用我的代码。最后附加到 w3wp.exe。现在尝试运行您的控制台应用程序,您应该会发现它在 w3wp.exe 中触发了异常。检查堆栈跟踪,看看是否能提供更多信息。

      使用转储文件

      您也可以尝试从故障转储中工作。诚然,这显然更加核心,但应该为您提供您所缺乏的细节。工具ProcDump 可以附加到 w3wp.exe(如果不使用 -s 开关),如果发生未处理的异常,将创建转储。如果您在使用 ProcDump 时遇到问题,请尝试 ADPlus,它会做类似的事情。

      从创建的转储文件中,使用this KB article 设置 WinDbg 并开始使用。在Tess Ferrandez's blog (Strategy #2)上有一个如何使用WinDbg的例子。

      【讨论】:

        【解决方案3】:

        您是否尝试过以提升的权限运行代码?

        II 是否有一些关于身份验证的时髦设置? (仅尝试 Windows 身份验证)

        【讨论】:

        • 提升的权限并没有解决它。 IIS 身份验证设置为没有匿名访问的集成 Windows 身份验证。
        【解决方案4】:

        不幸的是,有数百种方法可以生成此错误。只要问Google

        您可以考虑使用SPTraceView 来更好地描述错误。这是该工具的description 和解决此问题的example

        祝你好运!

        【讨论】:

          【解决方案5】:

          我有类似(不等于)的问题。我已经用这段代码解决了:

          using( SPSite site = ConnectToSharepointAsSystem() ) {
             // now should be all ok
          }
          
          // somewhere in helper class ->
          public static SPUserToken GetSystemToken(SPSite site) {
              SPUserToken token = null;
              bool tempCADE = site.CatchAccessDeniedException;
              try {
                  site.CatchAccessDeniedException = false;
                  token = site.SystemAccount.UserToken;
              }
              catch (UnauthorizedAccessException) {
                  SPSecurity.RunWithElevatedPrivileges(() => {
                      using (SPSite elevSite = new SPSite(site.ID))
                          token = elevSite.SystemAccount.UserToken;
                  });
              }
              finally {
                  site.CatchAccessDeniedException = tempCADE;
              }
              return token;
          }
          
          public static Microsoft.SharePoint.SPSite ConnectToSharepoint() {
              string urlSharepointSite;
              var ret = ConnectToSharepoint(out urlSharepointSite);
              return ret;
          }
          public static Microsoft.SharePoint.SPSite ConnectToSharepoint(out string urlSharepointSite) {
              urlSharepointSite = "http://www.domain.org";
              var site = new Microsoft.SharePoint.SPSite( urlSharepointSite );
              return site;
          }
          public static Microsoft.SharePoint.SPSite ConnectToSharepointAsSystem() {
              string urlSharepointSite;
              Microsoft.SharePoint.SPUserToken userToken = null;
              using (var tmpSite = CSharepointNastroje.PripojitNaSharepoint( out urlSharepointSite )) {
                  userToken = GetSystemToken(tmpSite);
              }
              var site = new Microsoft.SharePoint.SPSite(urlSharepointSite, userToken);
              return site;
          }
          

          【讨论】:

          • 根据我的经验,最好解决底层安全/配置问题,而不是围绕它进行编码。公平地说,有些情况下需要这样的代码。对我来说,OP 的情况更像是一个安全/配置问题。
          猜你喜欢
          • 2010-09-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多