Sharepoint 2010 将网站集添加到SharePoint 2010中以FBA身份登录的Web应用程序

Sharepoint 2010 将网站集添加到SharePoint 2010中以FBA身份登录的Web应用程序,sharepoint-2010,Sharepoint 2010,嗨 我正在尝试在web应用程序下创建网站集,该应用程序配置为基于声明的身份验证,代码如下: SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = SPContext.Current.Site) { using (SPWeb web = site.RootWeb) { site.AllowUnsafeUpdates = true; web.AllowUnsafeUpd

嗨 我正在尝试在web应用程序下创建网站集,该应用程序配置为基于声明的身份验证,代码如下:

SPSecurity.RunWithElevatedPrivileges(delegate {
  using (SPSite site = SPContext.Current.Site)
  {
    using (SPWeb web = site.RootWeb)
    {
      site.AllowUnsafeUpdates = true;
      web.AllowUnsafeUpdates = true;
      try
      {
        SPWebApplication web_App = web.Site.WebApplication;
        web_App.Sites.Add(SiteUrl, SiteTitle, Description, Convert.ToUInt32(Constants.LOCALE_ID_ENGLISH), SiteTemplate, OwnerLogin, "testuser", OwnerEmail);
      }
      catch (Exception ex)
      { 
        string s = ex.Message + " " + ex.StackTrace;
        throw;
      }
      finally
      {
        web.AllowUnsafeUpdates = false;
        site.AllowUnsafeUpdates = false;
      }
    }
  }
});
在这里,我将“OwnerLogin”传递为“CustomMembership:UserName”。但是web_App.Sites.Add抛出了一个wierd错误,如“ex={由于代码已优化或本机框架位于调用堆栈顶部,因此无法计算表达式。}”。非常感谢您在这方面提供的任何帮助。
问候,

Paddy

您的高程代码错误,您需要创建全新的SPSite和SPWeb引用。我给它们加上前缀“c”,以表明它在不同的上下文中

SPSecurity.RunWithElevatedPrivileges(delegate() {
    using (SPSite csite = new SPSite(SPContext.Current.Site.ID)) {
        using (SPWeb cweb = csite.OpenWeb(SPContext.Current.Site.RootWeb.ID)) {
            //do stuff
        }
    }
});

OwnerLogin
参数应包含CustomMembership:prefix-pass plain UserName作为该参数的值


顺便说一句,获取Web应用程序对象的方法不必要地复杂-请使用以下方法:

SPWebApplication webApplication = SPWebApplication.Lookup(new System.Uri("Web-Application-URL"));

我不认为这是问题的根源,但您不应该处理由
SPContext.Current.Site
属性返回的
SPSite
对象(即,使用删除第一个
)-它是从\u layouts文件夹中的aspx页面调用的。PaddyThanks马立克为这些提示。但这个问题仍然存在。我采纳了所有关于这个问题的建议,但没有一个是适合我的。帕迪(1)这篇文章详细讨论了一个类似的问题,它可能会给你一些想法。(2)您是否考虑过使用管理Web服务?我正在使用一个Web服务在FBA Web应用程序下创建网站集,它工作得很好。@Paddy在做了更多的研究和测试后,我开始认为不可能直接从放置在
\u layouts
文件夹中的
.aspx
页面创建新网站集。它可能需要一些网站集用户(FBA与否,这无关紧要)没有的特权-可能是服务器场管理员?在我看来,您必须使用内置的管理Web服务或创建自定义Web服务(请记住,它必须部署到
ADMISAPI
文件夹)。谢谢@Marek,我将尝试该选项。