当前位置: 首页>>WEB开发>>正文


以编程方式创建网站集会抛出异常<nativehr> 0x80070005</nativehr>

webfans WEB开发 , , , , , 去评论

问题描述

我将SharePoint自定义从MOSS 2007迁移到SharePoint Server 2010(Win 2008),它以编程方式创建网站集。问题是我无法使用下面的代码创建网站集。我已确保用于创建网站集的Web应用程序的应用程序池帐户是Farm Administrators组的成员,并在Web应用程序策略(CA)中作为完全控制(用户)添加。

我很确定这是由于权限,但我目前无能为力。所以,任何提示将不胜感激。

 SPSecurity.RunWithElevatedPrivileges(delegate()
 {
      using (SPSite tmpSite = new SPSite(site.ID))
      {
         using (SPWeb tmpWeb = tmpSite.OpenWeb(web.ID))  
          {
             SPWebApplication webApp = tmpWeb.Site.WebApplication;
             SPContentDatabase currentDB = webApp.ContentDatabases[webApp.ContentDatabases.Count - 1];
             tmpWeb.AllowUnsafeUpdates = true;

              try
              {
                  SPSite newsite= webApp.Sites.Add("sites/" + newWebUrl, title, itemDescription, 1053, "RSVArbetsgrupper#0", "testuser", "testuser", "test@mail.com");
                  properties.AfterProperties["WebbplatsURL"] = newsite.Url;

              }
              catch (Exception e)
              {
                  PortalLog.LogString("## Exception Occurred:ItemAdding Add New room** {0} || {1}", e.Message, e.StackTrace);
                                        properties.ErrorMessage = e.Message;
                                        properties.Cancel = true;                          
              }
          }
       }
   });

//我还提供了自定义配置提供程序类,在创建新的网站集时会调用它。发生问题的同时

linksList.EventReceivers.Add(SPEventReceiverType.ItemAdding,
                                              asmName,
                                              linksReceiverName);  

这是完整的课程:

 public class MyProvisioningProvider : SPWebProvisioningProvider
    {
        // <summary>
        // Gets called when a web is provisioning when the template
        // chosen has ProvisionAssembly and ProvionClass attributes
        // specified
        // </summary> 
        public override void Provision(SPWebProvisioningProperties props)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate(){
            using (SPWeb web = props.Web)
            {
                try
                {
                    // Create site from template'

                    web.AllowUnsafeUpdates = true;
                    web.ApplyWebTemplate("RSVArbetsgrupperHidden");   
                    SPList linksList = web.Lists["Länkar"];
                    string linksReceiverName = "NS_LinksItemEventReceiver";
                    linksList.EventReceivers.Add(SPEventReceiverType.ItemAdding,
                                              asmName,
                                              linksReceiverName);                         
                    AddListViewWebPart(web, linksList, "Right", 99, PartChromeType.Default, 0);                       
                    ApplyTheme(web, "RSV");
                    web.Update();                                               
                    web.AllowUnsafeUpdates = false;
                }

                catch (Exception e)
                {
                    PortalLog.LogString("## Exception Occurred:ItemAdding Add New room** {0} || {1}", e.Message, e.StackTrace);

                }
            }

            });
        }

    }

这是一个例外:

<nativehr>0x80070005</nativehr><nativestack></nativestack>
<nativehr>0x80070005</nativehr><nativestack></nativestack>
The site /sites/s9000002 could not be created.  The following exception occurred: <nativehr>0x80070005</nativehr><nativestack></nativestack>.

注意:我不打算使用管理服务来执行此任务。

我已经测试了用于为OOTB Site Templatee创建SC的相同代码,但仍然没有运气。代码中提到的自定义模板部署到WFE。

虽然我设法使用应用程序池帐户或开发人员帐户使用UI(中央管理)创建网站集。该问题仅在编程创建SC时发生。

ULS日志

Exception attempting to ApplyWebTemplate to SPSite 

Microsoft.SharePoint.SPException: Security validation of this page is invalid. Click the Back button in your browser, refresh the page and try again. ---> 

System.Runtime.InteropServices.COMException (0x8102006D): The security validation of this page is invalid. Click the Back button in your browser, refresh the page and try again. 
at Microsoft.SharePoint.Library.SPRequestInternalClass.RegisterEventReceiver (String bstrUrl, String bstrListName, event receiver surgical operation, Guid guidId, String bstrName, guidSiteId Guid, Guid guidWebId, guidHostId Guid, Int32 dwHostType, Int32 dwSynchronization, Int32 dwType, Int32 dwSequenceNumber, String bstrAssembly, String bstrClass, Guid solutionId, bstrData String, String bstrFilter, Int32 dwCredential, contextObjectId Guid, Guid contextType, contextEventType Guid, Guid contextId, Guid contextCollectionId) 
at Microsoft.SharePoint.Library.SPRequest.RegisterEventReceiver (String bstrUrl, String bstrListName, event receiver surgery surgery guidId Guid, String bstrName, guidSiteId Guid, Guid guidWebId, guidHostId Guid, Int32 dwHostType, Int32 dwSynchronization, Int32 dwType, Int32 dwSequenceNumber, bstrAssembly String, String bstrClass, Guid solutionId, bstrData String, String bstrFilter, Int32 dwCredential, contextObjectId Guid, Guid contextType , contextEventType Guid, Guid contextId, Guid contextCollectionId) --- End of inner exception stack trace --- 
at Microsoft.SharePoint.SPGlobal.HandleComException (COMException comex) 
at Microsoft.SharePoint.Library.SPRequest.RegisterEventReceiver (String bstrUrl, String bstrListName , Event Receivers surgery surgery, Guid guidId, String bstrName, Guid guidSiteId, Guid guidWebId, Guid guidHostId, Int32 dwHostType, Int32 dwSynchronization, Int32 dwType, Int32 dwSequenceNumber, String bstrAssembly, String bstrClass, Guid solutionId, String bstrData, String bstrFilter, Int32 dwCredential, Guid contextObjectId, contextType Guid, Guid contextEventType, contextId Guid, Guid contextCollectionId) 
at Microsoft.SharePoint.SPEventReceiverDefinition.RegisterForSiteOrWebOrList (Operation operation, Boolean isMigration) 
at Microsoft.SharePoint.SPEventReceiverDefinitionCollection.Add (SPEventReceiverType receiver type, String assembly, String className) at Logica_Types_001. ArbetsgruppProvisioningProvider.Provision (SPWebProvisioningProperties props) 
at Microsoft.SharePoint.SPWeb.ApplyWebTemplate (String strWebTemplate) at Microsoft.SharePoint.Administration.SPSiteCollection.Add (SPContentDatabase database, SPSiteSubscription siteSubscription, SITEURL String, String title, String description, UInt32 nLCID, String webTemplate , String owner login, String owner name, String owner email, String secondary contact login, String secondary contact name, String secondary contact email, String quotaTemplate, sscRootWebUrl String, Boolean useHostHeaderAsSiteName) Attempting to delete the site collection.

最佳解决方案

RunWithElevatedPrivileges需要它自己的SPWeb。如果您重新使用现有的SPWeb,则不会运行提升,而是使用初始上下文。

适用于您的代码的常用方法可以是:

public class MyProvisioningProvider : SPWebProvisioningProvider
{
    // <summary>
    // Gets called when a web is provisioning when the template
    // chosen has ProvisionAssembly and ProvionClass attributes
    // specified
    // </summary> 
    public override void Provision(SPWebProvisioningProperties props)
    {
        SPSecurity.RunWithElevatedPrivileges(delegate(){
        using (SPSite site = new SPSite(props.Web.Site.Id)) 
        {
        using (SPWeb web = site.OpenWeb(props.Web.Id))
        {
            try
            {
                // Create site from template'

                web.AllowUnsafeUpdates = true;
                web.ApplyWebTemplate("RSVArbetsgrupperHidden");   
                SPList linksList = web.Lists["Länkar"];
                string linksReceiverName = "NS_LinksItemEventReceiver";
                linksList.EventReceivers.Add(SPEventReceiverType.ItemAdding,
                                          asmName,
                                          linksReceiverName);                         
                AddListViewWebPart(web, linksList, "Right", 99, PartChromeType.Default, 0);                       
                ApplyTheme(web, "RSV");
                web.Update();                                               
                web.AllowUnsafeUpdates = false;
            }

            catch (Exception e)
            {
                PortalLog.LogString("## Exception Occurred:ItemAdding Add New room** {0} || {1}", e.Message, e.StackTrace);

            }
        }
        }
        });
    }
}

此代码创建反映相同对象的新SPSite和SPWeb对象,但具有提升的上下文。

[编辑]更多信息在RunWithElevatedPrivileges参考文献中,特别是:

An SPSite object created outside the delegate can be referenced inside the delegate, however, the methods and property assessors of the object run with the privileges of the user context in which the objects were created, not with the elevated privileges. The same point applies to SPWeb objects and any other objects. You must create new objects inside the delegate if you need to execute the members of the objects with elevated privileges. If the new object must represent the same persisted entity as an object created outside the delegate, then you must reference identification information from the externally created object and use it to create the new object within the delegate. For example, if web is a reference to an SPWeb object created before the call to RunWithElevatedPrivileges, then the following code shows you would use the ID of its parent SPSite object to construct a new SPSite object.

SPSecurity.RunWithElevatedPrivileges(delegate() {     using (SPSite site = new SPSite(web.Site.ID))     {     // implementation details omitted     } }); 

Important Important If secureCode includes any write operations, then the call to RunWithElevatedPrivileges should be preceded by a call of either SPUtility.ValidateFormDigest or SPWeb.ValidateFormDigest.

次佳解决方案

我相信,通过使用的构造函数,最后三个属性需要SPUser.LoginName,SPUser.Name和SPUser.Email。当这些参数不正确时,我在过去的网站创建代码中遇到了麻烦。

为什么你没有捕获catch块中的实际异常?

第三种解决方案

请点击SC创建详情链接 – http://blog.falchionconsulting.com/index.php/2009/07/custom-sharepoint-2007-site-collection-creation-page/。它描述了为用户收集网站的正确方式 – WFE(不是CA)。

第四种方案

  • 检查使用服务帐户运行的中心管理员

  • Do Site.WebApplication.FormDigestSettings.Enabled = false;

  • 确保applywebtemplate运行在长时间运行的过程中

参考资料

本文由朵颐IT整理自网络, 文章地址: https://duoyit.com/article/1493.html,转载请务必附带本地址声明。