有谁知道以编程方式为 Umbraco IContent 对象管理主机名的方法?
我需要从 csv 导入整个站点,并且需要自动从代码中设置主机名。
谢谢 !
也许这样的事情会帮助你?
var domain = new umbraco.cms.businesslogic.web.Domain("example.com")
{
RootNodeId = 1078,
Language = Language.GetByCultureCode("en-GB"),
};
domain.Save();
对于 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);