Mobile site problem

Editor
Aug 12, 2012 at 1:15 AM
Edited Aug 12, 2012 at 1:17 AM

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)  

Now if you go to main site http://www.thecodingguys.net you can see the ad on the left, this should NOT be rendered on the mobile layout page, how can I stop this?

Coordinator
Aug 17, 2012 at 1:20 AM
var wFile = (string)widget.wFile;
    
    if((MobileDevice==true && sectionName!="rcRight") || (MobileDevice==false)){ // <----- add this HERE
    
         if(sn!=sectionName)
.......
......
......

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

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

Manos
Feb 20, 2013 at 2:05 PM
Edited Feb 20, 2013 at 2: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 4: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 www.it-business.gr
Do you have any other idea to modify the MobileDevice = Request.Browser.IsMobileDevice; with something else

Thanks, Manos
Coordinator
Feb 20, 2013 at 5:12 PM
Edited Feb 20, 2013 at 5:12 PM
this may help:
http://stackoverflow.com/questions/1829089/how-does-ismobiledevice-work


or you can detect screen size - it may be easier

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

Manos