Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm taking my chances and only using 1 web application and 1 masterpage for my SharePoint site, which I'm now also optimizing for mobile devices.

I'm currently in the progress of developing a webcontrol to trim away all the webpartzones and webcontrol which I don't want to be downloaded to the mobile device.

I've read a bit about this, watched the Gavin & Chris session from the SharePoint 2011 convention in Anaheim, California. Since SharePoint Mobile is clearly not an option, since you get login prompted, my options is to create a Render-trimmer.

Request.Browser.IsMobileDevice seems to be the #1 choice for many developers, but I'm facing a problem where when my site is loaded on a cellphone it still renders all controls. I've set up some logging and it returns "IsMobileDevice = false" when loaded on a mobile device.

To get around this I'm now using Request.UserAgent, checking if it contains "Mobile". This works, seems to be pretty legit, but it leaves me wondering why Request.Browser.IsMobileDevice fails.

Is my solution really that legit? And why doesn't Request.Browser.IsMobileDevice work as intended? And are there, in your opinion, better ways of doing this, when using the same Web App and Masterpage regardlesss?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

glad that the session is of use to you, unfortunately we talked for way to long before we got onto the demos and they were rushed (infact there were a couple that I didn't show!)

Request.Browser.IsMobileDevice does work as intended.

The decives which will return true for this are determined by the compat.browser file in your web application. ASP.NET uses this file to determine what a given browser is capable of by pattern matching on the user agent that is supplied.

Now where thing could be getting confused is if you use the script from my blog that disables the mobile re-direction

What that script does is insert a line into the web.config which over-rides the IsMobile property for ALL browsers and sets it to false. Great in some scenarios, not so useful in others....

If you're looking to preserve the integrity of the IsMobile value from the compat.browsers file then you'll need to make sure you remove the 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>

From you web.config.

Then use the excellent approach that Waldek has to get around SharePoint wanting to re-direct mobile browsers

Hopefully this gets you going on the right path.

share|improve this answer

Check out Kyle's blog on responsive web design for SharePoint. Based on screen resolutions you can show/hide elements in your page

http://kyleschaeffer.com/sharepoint/v5-responsive-html5-master-page/

HTH

share|improve this answer

You can detect the browser(mobile or desktop) using a Httpmodule.

Also, the link can be helpful: http://msdn.microsoft.com/en-us/library/ms462572.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.