1

I have a website that detects mobile browsers and loads a different page to said devices. However, when I load the page in the UIWebView in my iphone app, it loads the default page instead of the mobile page. How can I tell the site that I'm a mobile browser?

My site is an ASP.NET site, with the following C# code implemented in each PageName.aspx.cs file for mobile redirecting:

if(Request.Browser["IsMobileDevice"] == "true")
{
     Response.Redirect("mResults.aspx");
}
else
{
     Response.Redirect("Results.aspx");
}
Andrew
  • 466
  • 2
  • 7
  • 22

1 Answers1

1

I believe what you want to do is change the User-Agent header for the request. The technique for doing that can be found in this question: Changing the userAgent of NSURLConnection.

EDIT:

Actually, I think your problem is that you're checking if Request.Browser["IsMobileDevice"] is equal to the String "true". This will never be the case. It should be a boolean value. If you replace your if condition with just Request.Browser["IsMobileDevice"], I think it might work. Like this:

if(Request.Browser["IsMobileDevice"])
{
     Response.Redirect("mResults.aspx");
}
else
{
     Response.Redirect("Results.aspx");
}

Documentation for this value is here: http://msdn.microsoft.com/en-us/library/system.web.configuration.httpcapabilitiesbase.ismobiledevice.aspx.

Community
  • 1
  • 1
Steven Oxley
  • 6,563
  • 6
  • 43
  • 55
  • Well, the site does load its mobile pages for Safari on an iPhone. The problem is only occurring in my app. But I'll give that a shot when I get the chance. – Andrew Mar 08 '12 at 20:36
  • OK - if it's working for Mobile Safari, then the User-Agent fix might work. I haven't been able to find additional info on what User-Agents ASP.NET considers 'Mobile'. I did find this, though, which may be helpful: http://www.useragentstring.com/pages/Safari/. – Steven Oxley Mar 08 '12 at 21:19
  • Thanks! I've been looking for something like that list, I was just setting the User-Agent to "Mobile" as a test run. – Andrew Mar 09 '12 at 19:32