有没有人知道以编程方式为Umbraco IContent对象管理主机名的方法?
我需要从csv导入整个网站,我需要自动从代码中设置主机名。
谢谢!
答案 0 :(得分:1)
也许这样的事情对你有帮助吗?
var domain = new umbraco.cms.businesslogic.web.Domain("example.com")
{
RootNodeId = 1078,
Language = Language.GetByCultureCode("en-GB"),
};
domain.Save();
答案 1 :(得分:1)
对于Umbraco 6+ API版本,这可能有一些用处 - 这是根据现有代码改编的 - 但你应该得到要点:
private readonly IDomainService _umbDomainService;
private readonly ILocalizationService _umbLocalizationService;
...
this._umbDomainService = ApplicationContext.Current.Services.DomainService;
this._umbLocalizationService = ApplicationContext.Current.Services.LocalizationService;
...
//Ensure the language:
var language = this._umbLocalizationService.GetLanguageByIsoCode(config.CultureInfo.Name);
if (language == null)
{
language = new Language("en-GB");
language.CultureName = "English UK, not sure used...";
this._umbLocalizationService.Save(language);
}
//TODO: Set the main language on the node...?
this._umbContentService.Save(rootTarget); //The root node using the domain
//Set the domain:
IDomain domain = new UmbracoDomain("www.example.com");
domain.LanguageId = language.Id;
domain.RootContentId = rootTarget.Id; //id of root node to apply domain to
_umbDomainService.Save(domain);