Sitecore Glass Mapper始终为null [英] Sitecore Glass Mapper always null
问题描述
我正在将Sitecore Glass Mapper用于我要设置的新项目. 我们正在使用Sitecore 7.2,用于Sitecore(TDS)代码生成的团队开发的最新版本以及最新版本的glass.
I am using Sitecore Glass Mapper for a new project I'm setting up. We are using Sitecore 7.2, latest version of Team Development for Sitecore (TDS) code generation and the latest version of glass.
我要执行的代码:
var b = new SitecoreContext();
var c = b.GetCurrentItem<T01_Homepage>();
b不为null. c为空.
b is not null. c is null.
var d = b.GetItem<T01_Homepage>("path")
d为空.
我在GlassMapperScCustom中添加了程序集:
I added my assembly in GlassMapperScCustom:
public static IConfigurationLoader[] GlassLoaders(){
var attributes = new AttributeConfigurationLoader(new[] { "Company.Framework.Websites.Corporate", "Company.Framework.Core", "Company.Framework.Common" });
return new IConfigurationLoader[] { attributes };
}
当我查看b.GlassContext.TypeConfigurations时,我所有的模型都在那里.
When I look into b.GlassContext.TypeConfigurations all my models are there.
我认为这可能是语言问题,因为该网站位于荷兰语,并且错误的语言可能无法正确解决.情况并非如此.
I figured it could be a language issue because the site is in dutch and maybe the wrong language would be resolved incorrectly. This was also not the case.
我禁用了WebActivator,并在Global.asax Application_Start方法中添加了GlassMapperSc.Start().
I disabled WebActivator and added the GlassMapperSc.Start() in my Global.asax Application_Start method.
我们还将Autofac用作DI框架.但是如果没有它,如上所示,它仍然无法正常工作.同样,当我创建自己的自定义模型而不生成TDS代码时,GetCurrentItem<T>
的结果为null.
We are also using Autofac as DI framework. But without it, it still isn't working as you can see above. Also when I create my own custom models without TDS code generation the result of GetCurrentItem<T>
is null.
有人知道我该如何解决吗?
Does anyone have an idea how I can fix this?
推荐答案
您是否检查了Sites.config和该网站的默认语言?您的Sitecore语言文件夹中定义的语言和您的配置可能有所不同.
Did you check your Sites.config and the default language for this website? There could be a difference between the language which is defined in your Sitecore languages folder and your configuration.
我的一个项目遇到了类似的问题,我将Sitecore.Context.Language更改为"nl"而不是"nl-NL".玻璃映射器将返回null,但在这种情况下,Sitecore.Context.Database.GetItem将返回一个对象.
I had a similar problem with one of my projects where I changed the Sitecore.Context.Language to "nl" instead of "nl-NL". The glass mapper will return null, but Sitecore.Context.Database.GetItem will return an object in this case.
这篇关于Sitecore Glass Mapper始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!