Mobile Channel Webforms

Vote:
 

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);
                HttpContext.Current.Response.End();

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...

#120351
Apr 15, 2015 14:52
Vote:
 

Take a look at http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/7/Content/Display-Channels/

#120355
Apr 15, 2015 15:10
Vote:
 

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

#120357
Apr 15, 2015 15:33
Vote:
 

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

#120358
Apr 15, 2015 15:35
Vote:
 

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;
                    }
                }
             }
            
        }



#120360
Apr 15, 2015 16:26
Vote:
 

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.

#120394
Apr 16, 2015 8:17
Vote:
 

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

#120403
Apr 16, 2015 9:59
Vote:
 

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>
    {

    }
#121997
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.