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
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...
Take a look at http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/7/Content/Display-Channels/
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
Easier is probably to hook up an event handler to TemplateResolver.TemplateResolved and exchange SelectedTemplate on the event argument.
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");
e.SelectedTemplate.Path = path;
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.
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.
You could do an early exit in your event handler if e.SelectedTemplate.TemplateTypeCategory != TemplateTypeCategories.WebFormsPage
Thanks Johan, Regarding 1, that works fine!
I followed this guide: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/8/Rendering/Display-channels/Changing-display-channel-programmatically/
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>