如何从 Umbraco 的特定文化中获取内容
How to get content from specific culture in Umbraco
我的双语网站将德语设置为默认语言,我正在尝试从我的 SurfaceController 中获取英语内容节点,如下所示:
Umbraco.Content(ID);
我曾尝试像这样改变当前的文化:
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
但是没有成功。
找到答案:
private readonly IVariationContextAccessor _variationContextAccessor;
public ContentApiController(IVariationContextAccessor variationContextAccessor)
{
_variationContextAccessor = variationContextAccessor;
}
public IHttpActionResult Get(int id, string culture)
{
_variationContextAccessor.VariationContext = new VariationContext(culture);
var cnt = Umbraco.Content(id);
return Ok(cnt.Name);
}
我的双语网站将德语设置为默认语言,我正在尝试从我的 SurfaceController 中获取英语内容节点,如下所示:
Umbraco.Content(ID);
我曾尝试像这样改变当前的文化:
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
但是没有成功。
找到答案:
private readonly IVariationContextAccessor _variationContextAccessor;
public ContentApiController(IVariationContextAccessor variationContextAccessor)
{
_variationContextAccessor = variationContextAccessor;
}
public IHttpActionResult Get(int id, string culture)
{
_variationContextAccessor.VariationContext = new VariationContext(culture);
var cnt = Umbraco.Content(id);
return Ok(cnt.Name);
}