English 中文(简体)
Sitefinity 4编程设置主题名称
原标题:Sitefinity 4 Set Theme Name Programmatically

在SiteFinity 4中,我们可以在用作页面模板的母版页面的页面加载中设置主题名称吗?

Best Wishes, Aki

问题回答

需要在asp.net中的Page_PreInit事件中设置页面主题

遗憾的是,母版页没有Page_PreInit事件,而这正是您需要设置主题的地方。

这是母版页本身的限制,而不是Sitefinity。

但是,可以在运行时通过创建自定义路由处理程序来拦截请求并动态修改主题,从而设置主题。

首先创建一个自定义管线类:

public class CustomRouteHandler : PageRouteHandler
{
    protected override void SetPageDirectives(Page handler, IPageData pageData)
    {
        base.SetPageDirectives(handler, pageData);

        var url = HttpContext.Current.Request.RawUrl.ToLower();
        var themeName = "AlternativeTheme"; 
        if (url.StartsWith("/alternative"))
            ThemeController.SetPageTheme(themeName, handler);

    }

    public static void RegisterType()
    {
        ObjectFactory.Container.RegisterType<PageRouteHandler, CustomRouteHandler>();
    }
}

然后,您需要在Global.asax文件中注册该路由:

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {

        Telerik.Sitefinity.Services.SystemManager.ApplicationStart += SystemManager_ApplicationStart;
    }

    void SystemManager_ApplicationStart(object sender, EventArgs e)
    {
        CustomRouteHandler.RegisterType();
    }
}

现在,每个请求都将通过该处理程序,您可以根据需要的任何自定义条件修改主题。

我计划写一篇博客文章和一段视频,详细介绍如何做到这一点以及你可以用它做什么,但这是它如何工作的基本理念。

我希望这是有帮助的!





相关问题
Problem installing Sitefinity 4 custom module

I m posting this here since I didn t get any support from the sitefinity forum. I created a new SiteFinity 4.0 project and added the Meeting module from the Intranet Starter Kit. Here s what I did: ...

Trouble with jQuery/jQuery UI and Sitefinity 4.0

I am trying to use jQuery.hide("#whatever .class").hide("slide", { direction: "right" }, 750); to slide previously hidden divs in and out (think scrolling portals)... In just a basic HTML template ...

How to debug Sitefinity 4.0 crashes?

I m new to Sitefinity and I want know how to approach debugging in general. I have a specific case here but my question is larger than this specific case. So here is my case: I ve created a ...

Sitefinity - ViewState + Life Cycle for controls?

I built a custom control that acts as a wizard and contains other controls within it. I built and tested the control using a blank asp.net webform page and everything was working perfectly. I add the ...

ASP.NET HttpHandler and WebResource.axd issues

I need a simple HttpHandler to handle specific non-existant paths in my ASP.NET project. I m using sitefinity 4. I wrote the handler but whenever I try to run the site, I get a frustrating error The ...

Error whilst publishing Sitefinity4 project

I m trying to deploy a Sitefinity 4 project. I have the main web app project, and two external class libraries. I ve tried to publish, and ive tried using a web deployment project, however both times ...

热门标签