Partilhar via


Blocking access to mobile view in SharePoint

Recently received a request from the cx where he wanted that whenever anyone tries to browse a SP URL with ?mobile=1 appended it should fallback to SP desktop site only i.e. should not take the user to mobile version of the site. As we all know there are 3 ways to block the mobile redirection in SP but all of these fail when a user directly adds ?mobile=1 query in the URL of the site.

 

1. In web.config of the web application add the following lines under configuration/system.web section

  • <browserCaps>
    <result type=”System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”/>
    <filter>isMobileDevice=false</filter>
    </browserCaps>

 

2. Modify the compat.browser of the web application found under C:\inetpub\wwwroot\wss\VirtualDirectories\<webapp>\App_Browsers

  • Code to change for each user agent 
    • <capability name=”isMobileDevice” value=”false” />

3.

Disable-SPFeature -Identity MobilityRedirect -Url https://yoursite

 

Note: None of the above method really block any user from directly accessing the mobile view of the site by simply appending ?mobile=1 in the URL

 

# To completely block the access we need to do the following:

 

# Install IIS URL rewriter module.

# add the below lines in your web.config of web application, just under the defaultdocuments tag

<rewrite>
<rules>
<rule name="test" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="*mobile=1" />
</conditions>
<action type="Redirect" url="{R:1}" appendQueryString="false" logRewrittenUrl="true" redirectType="Found" />
</rule>
</rules>
</rewrite>
<defaultDocument enabled="false">
<files>
<remove value="default.aspx" />
</files>

# same can be configured through GUI of URL rewriter as well