Various ways of Customizing the Mobile redirection feature in SharePoint 2010


In SharePoint 2010, there is a great in-built feature for mobile redirection which redirects the users accessing your SharePoint site from any mobile device. Unfortunately, the page where SharePoint redirects is not pretty to look at and also in most cases at enterprise levels, people would not want the users to show the “All Site Content Page” which is the default behavior of mobile redirection in SharePoint 2010. Now, SharePoint 2010 uses Bi-level redirection for mobile device. Those are:

  • IsMobileDevice property inside your web application’s Compat.browser file (Located at C:\inetpub\wwwroot\wss\VirtualDirectories\[Port No. for your web app]\App_Browsers) which is by default set to true.
  • A Hidden Feature called MobilityRedirect which can be activated using PowerShell command:
stsadmn -o activatefeature -name MobilityRedirect -url http://[your site url]

Now, Above methods will result in the redirection of your site for mobile devices which you can also test out from the desktop browser by appending /m/ after your site URL or by appending ?mobile=1. Now, These two will redirect you to two different pages of Mobile View. The first one (/m/) will redirect you to the default.aspx page located at m folder under the All Files of your site and the second one will redirect you to one of the pages (e.g; mblwp.aspx, mblwiki.aspx depending on your site definition and your home page) located inside the following folder:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\MOBILE

Let’s say that you don’t want your users to be redirect to the All Site Content Page which is located inside the above location. To do this, there are some tricks:

Firstly, you can grab the URL where the page is being redirected for mobile pages (?mobile=1) from most of the mobile devices and write a conditional statement to redirect the page to your customized homepage.

Secondly, you can write a custom HTTP handler and fool the SharePoint to change its behavior for your web application. (Remember, this will have effect on all the sites and site collections under that particular web application)

Thirdly, you can turn off the IsMobileDevice property inside the browser settings by setting its value to false.

Finally, you can turn off the hidden feature MobilityRedirect

First Method:

Now, First method is the quickest way to change the default behavior of your SharePoint site’s mobile redirection. To do this go the exact location where your site is being redirected which you can grab from the redirected URL from the mobile device or appending ?mobile=1 after your URL. Go inside the 14 hive\TEMPLATE\LAYOUTS\MOBILE and find out that particular aspx page. You will find the following method at the top of the page inside a script:

protected override Microsoft.SharePoint.SPBasePermissions RightsRequired

Change the code inside this method like the following:

get
    {
        string DevUrl = System.Web.HttpContext.Current.Request.Url.OriginalString.ToString();

        if(DevUrl=="http://dev-s2010:8800/" || DevUrl=="http://dev-s2010:8800/_layouts/mobile/mblwp.aspx?Url=%2Fdefault%2Easpx&mobile=1" || DevUrl=="http://dev-s2010:8800/_layouts/mobile/mblwp.aspx?Url=%2Fdefault%2Easpx")
        {
        Response.Redirect(http://www.customurl.com);   // your Custom URL for Mobile Redirection    
        }

        return base.RightsRequired | Microsoft.SharePoint.SPBasePermissions.ViewPages;
    }

Where http://dev-s2010 is my Site URL. In my case, I was being redirected to mblwp.aspx page.

After doing this, your site will be automatically redirected to the site mentioned inside redirection command. Now, remember, this cannot be a normal SharePoint site URL which will again redirect your user to the All Site Content Page.

Second Method:

As because the SharePoint mobile redirect is done at BeginRequest event (which is the first event in the Page Life Cycle of an ASP.NET page) handler in the SPRequestModule HTTP Module which is part of SP2010. You can write a custom HTTP module to mislead SharePoint making it think that you are using a non-mobile browser like below:

public class MobileRequestHttpModule : IHttpModule
{
    private HttpBrowserCapabilities browserCapabilities;
 
    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
        context.AuthenticateRequest += new EventHandler(context_AuthenticateRequest);
    }
 
    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = sender as HttpApplication;
        browserCapabilities = application.Request.Browser;
        application.Request.Browser = new MobileBrowserCapabilities(browserCapabilities);
    }
 
    void context_AuthenticateRequest(object sender, EventArgs e)
    {
        HttpApplication application = sender as HttpApplication;
        application.Request.Browser = browserCapabilities;
    }
 
    public void Dispose()
    {
    }
}

Using this module we can hook up to the BeginRequest event and temporarily substitute the browser information with our own. The substitute is defined by the MobileBrowserCapabilities class and contains the most of the original information about the current browser except for the one:

public class MobileBrowserCapabilities : HttpBrowserCapabilities
{
    public override bool IsMobileDevice
    {
        get
        {
            return false;
        }
    }
 
    public MobileBrowserCapabilities() { }
 
    public MobileBrowserCapabilities(HttpBrowserCapabilities browserCaps) : this()
    {
        if (browserCaps.Adapters != null && browserCaps.Adapters.Count > 0)
        {
            foreach (object key in browserCaps.Adapters.Keys)
            {
                Adapters[key] = browserCaps.Adapters[key];
            }
        }
 
        Capabilities = browserCaps.Capabilities;
        HtmlTextWriter = browserCaps.HtmlTextWriter;
    }
}

Now, this will also work for all the sites and site collections for that particular web application. So, if you want the default mobile redirection feature for any of your site and site collections, you won’t be able to do that as it works at web application level. To read about more about this particular technique, follow This Article mentioned by Waldek Mastykarz.

Third Method:

If you want to disable the mobile redirection for your site at the web application level (For all sites and site collections of that Web App), there is another way by which you can permanently disable the Mobile Redirection which is to change the property of IsMobileDevice  inside Compat.browser inside the following directory:

C:\inetpub\wwwroot\wss\VirtualDirectories\[ Port No of Web App]\App_Browsers

Find the following line under every browser settings category:

<capability name="isMobileDevice"                    value="true" />

Change the value to value=”false” for every section of browser types.

This is work right away without resetting the IIS.

Fourth method:

If you want to disable the hidden feature for MobilityRedirect, you can do so by running the following command in PowerShell:

stsadmn -o deactivatefeature -name MobilityRedirect -url http://[your site url]

This method will probably not work for the Internet Facing sites as it will still redirect the users to the All Site Content Page.

Now, there is another way for redirection recommended by MSDN which is only possible for the homepage of your site. But for that to happen, one needs to type in upto default.aspx or append /m/ after the URL. The article can be found here ( I have already tested this method and it works).

So far, these are the techniques I have discovered Mobile Redirection for a SharePoint site. I would appreciate if someone has a different or better solution. Till then, we have to be satisfied with these inconvenient methods provided by Microsoft. Good Luck!

Advertisements

3 thoughts on “Various ways of Customizing the Mobile redirection feature in SharePoint 2010

  1. You can also do this by making a SPWebConfigModification the PowerShell way.

    begin {
    [void][reflection.assembly]::LoadFile(“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll”)
    Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0
    }
    process {
    $WebApplication = Get-SPWebApplication “https://site.com”

    $configMod = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
    $configMod.Path = “configuration/system.web”
    $configMod.Name = “browserCaps”
    $configMod.Sequence = 0
    $configMod.Type = 0
    $configMod.Value = ” ”
    $configMod.Owner = “rwd”

    $configMod1 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
    $configMod1.Path = “configuration/system.web/browserCaps”
    $configMod1.Name = “result”
    $configMod1.Sequence = 0
    $configMod1.Type = 0
    $configMod1.Value = “isMobileDevice=false”
    $configMod1.Owner = “rwd”

    $WebApplication.WebConfigModifications.Add($configMod)
    $WebApplication.WebConfigModifications.Add($configMod1)
    $WebApplication.Update()
    $WebApplication.Parent.ApplyWebConfigModifications()
    $WebApplication.WebConfigModifications.Clear()
    }
    end {
    Start-Sleep -Seconds 10
    $WebApplication = Get-SPWebApplication “https://site.com”
    $WebApplication.WebConfigModifications | where {$_.Owner -eq ‘rwd’} | fl
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s