Developer Forum »
Mobile switching
58 posts

I have enabled mobile support in settings and added a new provider with custom detection of mobile devices. It is now selected as provider in settings. I was expecting that Webnodes automatically redirected to the mobile template when the user-agent was considered "true" in the provider? Am I mistaken? Do I have to manually redirect?

 

181 posts

There was a bug in one version where there were some situations when the custom provider wasn't called. We rewrote much of the code recently in build 1417, to make it easier to override, not just the detection, but the complete handling of different devices and templates.

Are you using a newer version than 1417? Are you using Webforms or MVC?

Einar Olav at your company has already used it in a project.

58 posts

I am using build 1433 with webforms.

181 posts

Could it be that you have a cookie on your machine where you have selected the desktop version at one time?

If there is a cookie where it is specified that it should use the desktop/normal version, it will never run the detection code or redirect to mobile.

58 posts

Hmmm.. I checked after I sent my last reply, and the cookie had been set (waf_pref_client). I wasn't aware it automatically assigned the cookie even though I'm not adding the waf_client param in the querystring. I thought I had to explicitly set this cookie. I just have to clear the cookie when changing user agent during testing then :) is it possible to disable the cookie-creation temporarily?

Thanks :)

181 posts

The easiest way to disable the cookie creation is to override the method GetRelativePathOfTemplateFile on the template content class. The code inside that method looks like this:

 if (WAFRuntime.Installation.EnableMobileSupport && FilepathMobile.Length > 0 && UseMobileTemplate(true)) {
                WAFContext.Request.IsMobile = true;
                return FilepathMobile;
            } else {
                return Filepath;
            }

The UseMobileTemplate method call have a useCookies parameter that you can change to false. 

Since Template is a built-in content class, you can't override the GetRelativePathOfTemplateFile directly, you have to create new content class that inherits from Template, and add the override there.

We'll add a simpler option to override the cookie handling later.

58 posts

Great! :) thanks a bunch!

1