1
我需要根据特定规则设置当前语言。我需要访问当前页面和当前用户才能作出决定。我查看了文档并it said在PageBase上使用了InitializeCulture方法。我的项目使用MVC而不是WebForms,相当于MVC中的InitializeCulture是什么?自定义语言处理EPiServer
我需要根据特定规则设置当前语言。我需要访问当前页面和当前用户才能作出决定。我查看了文档并it said在PageBase上使用了InitializeCulture方法。我的项目使用MVC而不是WebForms,相当于MVC中的InitializeCulture是什么?自定义语言处理EPiServer
您可以实现IAuthorizationFilter并在OnAuthorization中执行检查。也可以在IActionFilter中完成,但OnAuthorization会在前面调用。您将有权访问当前的HttpContext并从那里获取当前页面数据。
public class LanguageSelectionFilter : IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
// access to HttpContext
var httpContext = filterContext.HttpContext;
// the request's current page
var currentPage = filterContext.RequestContext.GetRoutedData<PageData>();
// TODO: decide which language to use and set them like below
ContentLanguage.Instance.SetCulture("en");
UserInterfaceLanguage.Instance.SetCulture("en");
}
}
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
// register the filter in your FilterConfig file.
filters.Add(new LanguageSelectionFilter());
}
}
谢谢!这看起来像我之后的事情。我们设法摆脱了EPiServer中的正常回退行为,而我的问题是由于EPiServer中的错误。如果我在法语网页上,并在我的视图中调用瑞典语页面,如下面的@ Url.PageUrl(page.LinkURL)。事实证明,即使页面是瑞典的,“LinkURL”实际上包含“epslanguage = fr”。我通过使用我自己的Url的HtmlHelper解决了这个问题:https://gist.github.com/anonymous/8565072 – Andreas
这很好理解,谢谢! – aolde