Sitecore Glass Mapper始终为null

Han*_*aud 6 code-generation sitecore tds glass-mapper sitecore7.2

我正在使用Sitecore Glass Mapper来创建我正在设置的新项目.我们正在使用Sitecore 7.2,最新版本的Team Development for Sitecore(TDS)代码生成和最新版本的玻璃.

我试图执行的代码:

var b = new SitecoreContext();
var c = b.GetCurrentItem<T01_Homepage>();
Run Code Online (Sandbox Code Playgroud)

b不为空.c为空.

var d = b.GetItem<T01_Homepage>("path")
Run Code Online (Sandbox Code Playgroud)

d为空.

我在GlassMapperScCustom中添加了我的程序集:

public static IConfigurationLoader[] GlassLoaders(){            

    var attributes = new AttributeConfigurationLoader(new[] { "Company.Framework.Websites.Corporate", "Company.Framework.Core", "Company.Framework.Common" });

    return new IConfigurationLoader[] { attributes };
}
Run Code Online (Sandbox Code Playgroud)

当我查看b.GlassContext.TypeConfigurations时,我所有的模型都在那里.

我认为它可能是一个语言问题,因为该网站是荷兰语,也许错误的语言将被错误地解决.事实并非如此.

我禁用了WebActivator并在我的Global.asax Application_Start方法中添加了GlassMapperSc.Start().

我们也使用Autofac作为DI框架.但如果没有它,它仍然无法正常工作,如上所述.此外,当我创建自己的自定义模型而没有生成TDS代码时,结果GetCurrentItem<T>为null.

有谁知道如何解决这个问题?

Ald*_*tev 2

您检查过您的 Sites.config 和该网站的默认语言吗?Sitecore 语言文件夹中定义的语言与您的配置之间可能存在差异。

我的一个项目也遇到了类似的问题,我将 Sitecore.Context.Language 更改为“nl”而不是“nl-NL”。glass 映射器将返回 null,但在这种情况下 Sitecore.Context.Database.GetItem 将返回一个对象。