【问题标题】:Custom language handling EPiServer自定义语言处理 EPiServer
【发布时间】:2014-01-16 11:32:55
【问题描述】:

我有根据具体规则设置当前语言的需求。我需要访问当前页面和当前用户才能做出决定。我查看了文档和it said 以在 PageBase 上使用 InitializeCulture 方法。我的项目使用的是 MVC 而不是 WebForms,MVC 中 InitializeCulture 的等价物是什么?

【问题讨论】:

    标签: episerver-7


    【解决方案1】:

    您可以实现 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”,即使该页面是瑞典语页面。我使用自己的 HtmlHelper 解决了这个问题:gist.github.com/anonymous/8565072
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 2018-07-05
    • 2020-11-24
    • 2015-04-22
    • 1970-01-01
    • 2015-06-16
    相关资源
    最近更新 更多