【问题标题】:Sitecore Error: Could Not read Sitecore ConfigurationSitecore 错误:无法读取 Sitecore 配置
【发布时间】:2017-02-20 00:21:31
【问题描述】:

我正在尝试使用 Visual Studio 解决方案创建新的 Sitecore 项目。但是当我调用主数据库时,我收到错误Could Not read Sitecore Configuration。我知道这个问题已经被问过了,但我不清楚提供的解决方案。

谁能指导我准确了解哪些发布值可能会被我的 web.config 文件覆盖,以便我进行更正。

提供的另一个解决方案是为网站文件夹上的 IIS 用户提供编辑/修改访问权限。它对我不起作用。

public class MyItem
{
    public void CreateItem()
    {
        using (new Sitecore.SecurityModel.SecurityDisabler())
        {
            Sitecore.Data.Database masterDB = Factory.GetDatabase("master");               
            Item parentItem = masterDB.GetItem(new ID("{140DC116-E743-4C02-9F08-CB73151A5163}"));
            TemplateItem template = masterDB.GetTemplate(new ID("{C9B284A6-0427-4296-8217-E8A3F728D8F0}"));

            parentItem.Add("RanjitAsset1", template);

        }
    }
}

【问题讨论】:

  • 您可以将您正在使用的代码添加到问题中吗?
  • 是的,这是我的代码:
  • 我看不到代码。
  • 将代码添加到您的原始问题中。在 cmets 中添加代码使其非常难以阅读。
  • 好的,你能检查一下你的主数据库连接字符串名称吗?它是“主”吗?

标签: sitecore sitecore8 sitecore-mvc


【解决方案1】:

安德烈是正确的。检查 web.config,从 Visual Studio 发布时它可能已被覆盖。

<site 
        name="website" 
        virtualFolder="/"
        physicalFolder="/" 
        rootPath="/sitecore/content"
        startItem="/home"
        language="en" 
        **database="web"** 
        domain="extranet" 
        allowDebug="true" 
        cacheHtml="true" 
        htmlCacheSize="10MB" 
        enablePreview="true"
        enableDebugger="true" />

如果要切换数据库名称,可以使用桌面模式进行。或者,通过添加 ?sc_content=[database] 作为查询字符串参数。

使用API​​,您可以使用SoteContext 切换上下文,并获取Item。另外,使用 SelectSingleItem 方法,它会在文件夹中查找一个 Item,如果存在,它会更新它,否则它会创建它。

<!-- language: lang-cs -->  
public class MyItem
{
    public void CreateItem()
    {
        SiteContext targetSiteContext = SiteContext.GetSite(sitename);
        using (var context = new SiteContextSwitcher(targetSiteContext))
        {
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                // do something on the new site context
                var title = @"You title goes here";
                var parentItem = Sitecore.Context.Database.GetItem(new Data.ID("{140DC116-E743-4C02-9F08-CB73151A5163}"));
                var template = Sitecore.Context.Database.GetTemplate(new Data.ID("{C9B284A6-0427-4296-8217-E8A3F728D8F0}"));
                var newItem = Sitecore.Context.Database.SelectSingleItem(parentItem.Paths.Path + "//*[@@name='" + title + "']") ?? template.CreateItemFrom(title, parentItem);
                try
                {
                    newItem.Editing.BeginEdit();
                    newItem.Fields["NewsTitle"].Value = title;
                    //Rest of the fields go here
                    newItem.Editing.AcceptChanges();
                    newItem.Editing.EndEdit();
                }
                catch (Exception ex)
                {
                    Diagnostics.Log.Error("Crawl Error: ", ex);
                    newItem.Editing.CancelEdit();
                }
            }
        }
    }
}

【讨论】:

    【解决方案2】:

    出现问题的原因可能是您的 web.config 在您从 VS 发布解决方案后被默认的 ASP.net web.config 覆盖。

    您能否将您的网站 web.config 文件与干净的 sitecore 安装中的文件进行比较?

    【讨论】:

      猜你喜欢
      • 2014-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-30
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2015-07-01
      相关资源
      最近更新 更多