使用FBA以编程方式创建Content数据库 [英] Create Content database programatically using FBA

查看:115
本文介绍了使用FBA以编程方式创建Content数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想以编程方式创建内容数据库.我尝试使用SPSecurity.RunWithElevatedPrivileges代码,但它给出了 Access Denied 异常.该网站是使用基于声明的身份验证创建的.

以下是我的代码:

Hi
I want to create content database programatically. I have tried using SPSecurity.RunWithElevatedPrivileges code but it gives Access Denied exception. The site is created using claim based authentication.

Below is my code:

SPSite site=SPContext.Current.Site;
SPSecurity.RunWithElevatedPrivileges(delegate()
  {
      using (SPSite elevatedSite = new SPSite(site.ID))
        {
            SPWebApplication elevatedWebApp = elevatedSite.WebApplication;
            elevatedWebApp.ContentDatabases.Add(serverName, dbName, null, null, 0, 1, 1);
        }
  });


推荐答案

通常,如果所访问的对象不是在SPSecurity.RunWithElevatedPrivileges块内创建的,或者实现没有赋予权限,则代码将不会在提升的特权下运行.用户帐户处理代码执行.

在这里查看类似的讨论:
将代码作为wcf服务远程执行时,访问被拒绝 [ ^ ]
SPSecurity.RunWithElevatedPrivileges中的访问被拒绝 [ ^ ]
Generally, the code will not run within elevated privilege if the object accessed was not created within the SPSecurity.RunWithElevatedPrivileges block OR the implementation is not giving privileges to right user account handling the code execution.

Look at similar discussions here:
Access denied when code is executed remotely as a wcf service[^]
Access denied within SPSecurity.RunWithElevatedPrivileges[^]
SPSecurity.RunWithElevatedPrivileges - an important point while using it in web context[^]


您的SPSite变量在提升的块之外.还需要包含它,如下所示:
You SPSite variable is outside the elevated block. It also needs to be included, like this:
SPSecurity.RunWithElevatedPrivileges(delegate() {
    using (SPSite site = new SPSite(SPContext.Current.Site.ID)) {
        using (SPWeb web = site.OpenWeb(SPContext.Current.Site.RootWeb.ID)) {
            // ...
        }
    }
});


祝你好运!


Good luck!


这篇关于使用FBA以编程方式创建Content数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆