2

我有将德语设置为默认语言的双语网站,我正在尝试从我的 SurfaceController 获取英语内容节点,如下所示:

Umbraco.Content(ID);

我试图像这样改变当前的文化:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

但没有成功。

4

1 回答 1

5

找到了答案:

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);
}
于 2019-09-23T12:37:04.910 回答