Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sitecore错误:无法读取Sitecore配置_Sitecore_Sitecore8_Sitecore Mvc - Fatal编程技术网

Sitecore错误:无法读取Sitecore配置

Sitecore错误:无法读取Sitecore配置,sitecore,sitecore8,sitecore-mvc,Sitecore,Sitecore8,Sitecore Mvc,我正在尝试使用Visual Studio解决方案创建新的Sitecore项目。但是当我调用master database时,我得到一个错误无法读取Sitecore配置。我知道已经有人问过这个问题,但我不清楚提供的解决方案 有人能告诉我哪些发布值可能会被我的web.config文件覆盖,以便我更正它吗 提供的另一个解决方案是为IIS用户在网站文件夹上提供编辑/修改权限。这对我不起作用 公共类MyItem { public void CreateItem() { 使用(新Sitecore.Secur

我正在尝试使用Visual Studio解决方案创建新的Sitecore项目。但是当我调用master database时,我得到一个错误
无法读取Sitecore配置。我知道已经有人问过这个问题,但我不清楚提供的解决方案

有人能告诉我哪些发布值可能会被我的web.config文件覆盖,以便我更正它吗

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

公共类MyItem
{
public void CreateItem()
{
使用(新Sitecore.SecurityModel.SecurityDisabler())
{
Sitecore.Data.Database masterDB=Factory.GetDatabase(“master”);
Item parentItem=masterDB.GetItem(新ID({140DC116-E743-4C02-9F08-CB73151A5163}));
TemplateItem template=masterDB.GetTemplate(新ID({C9B284A6-0427-4296-8217-E8A3F728D8F0}));
添加(“RanjitAsset1”,模板);
}
}
}

出现此问题的原因可能是,在从VS发布解决方案后,默认情况下ASP.netweb.config将覆盖您的web.config


您是否可以将您的网站web.config文件与clean sitecore安装中的文件进行比较?

可能会出现问题,因为您的web.config在从VS发布解决方案后,默认情况下会被ASP.netweb.config覆盖


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

Andrey是正确的。检查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切换上下文,并获取项目。另外,使用SelectSingleItem方法,它在文件夹中查找项目,如果存在,它将更新它,否则,它将创建它

<!-- 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();
                }
            }
        }
    }
}

公共类MyItem
{
public void CreateItem()
{
SiteContext targetSiteContext=SiteContext.GetSite(sitename);
使用(var-context=new-SiteContextSwitcher(targetSiteContext))
{
使用(新Sitecore.SecurityModel.SecurityDisabler())
{
//在新站点上下文中执行某些操作
var title=@“您的标题在这里”;
var parentItem=Sitecore.Context.Database.GetItem(new Data.ID(“{140DC116-E743-4C02-9F08-CB73151A5163}”);
var template=Sitecore.Context.Database.GetTemplate(新的Data.ID(“{C9B284A6-0427-4296-8217-E8A3F728D8F0}”);
var newItem=Sitecore.Context.Database.SelectSingleItem(parentItem.Path.Path+“/*[@@name=”+“+title+”]”)模板。CreateItemFrom(title,parentItem);
尝试
{
newItem.Editing.BeginEdit();
newItem.Fields[“NewsTitle”]。值=标题;
//其余的田地都在这里
newItem.Editing.AcceptChanges();
newItem.Editing.EndEdit();
}
捕获(例外情况除外)
{
Diagnostics.Log.Error(“爬网错误:”,ex);
newItem.Editing.CancelEdit();
}
}
}
}
}

安德烈是正确的。检查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切换上下文,并获取项目。另外,使用SelectSingleItem方法,它在文件夹中查找项目,如果存在,它将更新它,否则,它将创建它

<!-- 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();
                }
            }
        }
    }
}

公共类MyItem
{
public void CreateItem()
{
SiteContext targetSiteContext=SiteContext.GetSite(sitename);
使用(var-context=new-SiteContextSwitcher(targetSiteContext))
{
使用(新Sitecore.SecurityModel.SecurityDisabler())
{
//在新站点上下文中执行某些操作
var title=@“您的标题在这里”;
var parentItem=Sitecore.Context.Database.GetItem(new Data.ID(“{140DC116-E743-4C02-9F08-CB73151A5163}”);
var template=Sitecore.Context.Database.GetTemplate(新的Data.ID(“{C9B284A6-0427-4296-8217-E8A3F728D8F0}”);
var newItem=Sitecore.Context.Database.SelectSingleItem(parentItem.Path.Path+“/*[@@name=”+“+title+”]”)模板。CreateItemFrom(title,parentItem);
尝试
{
newItem.Editing.BeginEdit();
newItem.Fields[“NewsTitle”]。值=标题;
//其余的田地都在这里
newItem.Editing.AcceptChanges();
newItem.Editing.EndEdit();
}
捕获(例外情况除外)
{
Diagnostics.Log.Error(“爬网错误:”,ex);
newItem.Editing.CancelEdit();
}
}
}
}
}

您能将您正在使用的代码添加到问题中吗?是的,这是我的代码:我看不到代码。请将代码添加到原始问题中。在注释中添加代码会使阅读变得非常困难。好的,你能检查你的主数据库连接字符串名称吗。它是“主”吗?你能将你正在使用的代码添加到问题中吗?是的,这是我的代码:我看不到代码。将代码添加到原始问题中。在注释中添加代码会使阅读变得非常困难。好的,你能检查你的主数据库连接字符串名称吗?它是“主”吗?