Mobile site problem

Aug 12, 2012 at 2:15 AM
Edited Aug 30, 2014 at 9:14 PM
I setup mobile website but I got one problem, in the default.cshtml I got this code: //set layout for requested page string strUserAgent = Request.UserAgent.ToString().ToLower(); bool MobileDevice = Request.Browser.IsMobileDevice; if(Request.Cookies["MobileDevice"] != null){ if (Request.Cookies["MobileDevice"].Value == "IgnoreMobile" ){ MobileDevice = false; } } else { if (strUserAgent != null){ if (MobileDevice == true || strUserAgent.Contains("iphone") || strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") || strUserAgent.Contains("android") || strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") || strUserAgent.Contains("palm")) { Layout="~/rcLayouts/Mobile/_SiteLayout.cshtml"; }else{ Layout = "~/rcLayouts/"+ data.pMasterpage; } } } Now if it detects mobile it loads _SiteLayout.cshtml sheet, the problem is it renders a sectionc called  @RenderSection("rcRight", false) how can I stop this?
Aug 17, 2012 at 2:20 AM
var wFile = (string)widget.wFile;
    if((MobileDevice==true && sectionName!="rcRight") || (MobileDevice==false)){ // <----- add this HERE

  sn = sectionName;
    } // <---- close if HERE
Feb 18, 2013 at 7:53 PM
Edited Feb 18, 2013 at 8:03 PM

I try to do this on my site without succes maybe because I have many sections
How to you write the code for more sections something like this:
if((MobileDevice==true && sectionName!="rcContColumn1" && sectionName!="rcContColumn2" && sectionName!="rcSlider") && sectionName!="rcLeft" || (MobileDevice==false)){

The curious is that on localhost it is working but on server not

Feb 20, 2013 at 3:05 PM
Edited Feb 20, 2013 at 3:19 PM
Just deleted my last post, sorry i need coffee or something :)

Your code should look like this:
if((MobileDevice==true && sectionName!="rcContColumn1" && sectionName!="rcContColumn2" && sectionName!="rcSlider" && sectionName!="rcLeft") || (MobileDevice==false)){

and it is working just fine like that. Set
bool MobileDevice = true;
at the top to test it, if it is not working on the server maybe it does not recognize device as mobile... so set it to true in the code just to see if it will work
Feb 20, 2013 at 5:26 PM
Thanks for your answer,
The problem is that it loads the correct layout but it loads also the sections that I would like to ignore
Do you wish to see the code of the default file

With bool MobileDevice = Request.Browser.IsMobileDevice;
On the iphone it is OK
On the Ipad it loads the correct design but also the sections
On opera mobile on Nokia symbian it loads the Web Layout
On IE it ok loads the Web Layout
On firefox is is OK loads the Web Layout

With bool MobileDevice = true;
Everything it is OK it loads the correct mobile design and it ignores the section
the link is
Do you have any other idea to modify the MobileDevice = Request.Browser.IsMobileDevice; with something else

Thanks, Manos
Feb 20, 2013 at 6:12 PM
Edited Feb 20, 2013 at 6:12 PM
this may help:

or you can detect screen size - it may be easier

or use jquery mobile
Feb 20, 2013 at 6:19 PM
Thanks I will try to detect screen size or use jquery mobile