2014-02-28 46 views
0

我想在外部MVC应用程序中使用Umbraco ContentService。你必须设置单身'Umbraco.Core.Persistence.SqlSyntax.SyntaxConfig'

在我的控制器:

var contentService = new ContentService(); 
var document = contentService.GetById(idofdocumenthere); 

我把我一把umbraco在web.config文件中的connectionString与providerName="System.Data.SqlClient

这是运行此代码后,我得到的错误:

You must set the singleton 'Umbraco.Core.Persistence.SqlSyntax.SyntaxConfig' 
to use an sql syntax provider 

Parameter name: SqlSyntaxProvider 

我也查this link,但这并没有工作。

提前致谢!

回答

0

不要实例化新的ContextService,请使用ApplicationContext.Current.Services.ContentService。

+0

您的意思是:'ApplicationContext.Current.Services.ContentService',但ApplicationContext.Current始终为空。我怎样才能解决这个问题? – Sllix

+0

是的,我的意思是.current!修正了上面的问题:-)如果您在webcontext中运行,它不能为空。如果它为空,则Web应用程序无法正确引导! ApplicationContext.Current当IIS启动网站时。 – dampee