SaaS CMS has officially launched! Learn more now.

Mobile Channel Webforms


Upgrade 6r2 to 7.19.2 webforms solution

In CMS 6R2 WebForms we built a mobile channel just by making a startpage.resp.aspx version of the startpage.aspx template and used same codebehindfile. Worked fine.

Then on preinit if mobile then Server.TransferRequest

HttpContext.Current.Server.TransferRequest("/Templates/Pages/StartPage.resp.aspx?id=6022&epslanguage=en", true);

in CMS version 7.19 you can activate ClassicLinkRoute. Fine. The problem is that it dont care about anything but the id param.

I can type in my browser "/Templates/Pages/whatever.aspx?id=6022&epslanguage=en" and it renders the CurrentPage default template.

How can i manage to have a mobile channel (different HTML output) with the same URL?
Should i override ClassicLinkRoute?

Build an own Route?

Please point me to the right direction...

Apr 15, 2015 14:52

Take a look at

Apr 15, 2015 15:10

Applicable on blocks. Not on an entire aspx-page.

Im thinking of a custom route that changes the MappedUrl of the ContentReference in runtime.... is that posible? hmm

Apr 15, 2015 15:33

Easier is probably to hook up an event handler to TemplateResolver.TemplateResolved and exchange SelectedTemplate on the event argument.

Apr 15, 2015 15:35

Thats just what i was looking for! And i can set it globaly... great stuff! Will just dig into every senario. Maybe i can even remove ClassicLinkRoute.

protected void Application_Start(object sender, EventArgs e)

            var templateResolver = ServiceLocator.Current.GetInstance<EPiServer.Web.TemplateResolver>();
            templateResolver.TemplateResolved += new EventHandler<EPiServer.Web.TemplateResolverEventArgs>(TemplateResolved);

        public void TemplateResolved(object sender, EPiServer.Web.TemplateResolverEventArgs e)
            if (IsMobileDevice)// my own implementation
                if (e != null && e.SelectedTemplate != null && e.SelectedTemplate.Path != null)
                    if (e.SelectedTemplate.Path.Contains(".aspx") && !e.SelectedTemplate.Path.Contains(".resp.aspx"))
                        string path = e.SelectedTemplate.Path.Replace(".aspx", ".resp.aspx");
                        if (!e.SelectedTemplate.Path.Equals(path))
                            e.SelectedTemplate.Path = path;

Apr 15, 2015 16:26

Two reflections:

1. When changed, it seems that e.SelectedTemplate.Path is being cached in memory, so i need to redo the path If NOT IsMobileDevice.

2. TemplateResolved is called many more times, mainly from when the PageTreeMenu is DataBound(), should i bother changing that, by checking Callstack: stackTrace.GetFrames();, but that seems not productive.

Apr 16, 2015 8:17

Regarding 1:

I should not recommend that you modify anything on the SelectedTemplate that is passed on the event argument (since as you say it is global and any change will affect other requests). Instead I would suggest to have two templates (e.g. in webforms something inheriting TemplatePage<T> where T is your model/page, in your case it could be your .aspx and .resp.aspx where the .resp.aspx could be tagged with mobile to avoid that it gets used by default). Then in the eventhandler you would replace e.SelectedTemplate with the mobile one that should be available in e.SupportedTemplates.

Regarding 2:

You could do an early exit in your event handler if e.SelectedTemplate.TemplateTypeCategory != TemplateTypeCategories.WebFormsPage

Apr 16, 2015 9:59

Thanks Johan, Regarding 1, that works fine!

I followed this guide:

but since we do use the same codebehind for .resp.aspx and .aspx I just made a fake class to register the TemplateDescriptor like this:

 [TemplateDescriptor(Path = "~/Templates/.../MyPage.resp.aspx", Name = "ResponsiveTemplate")]
    public class MyPageResp : TemplatePage<InfoMyPage>

May 25, 2015 8:18
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.