Reputation: 466
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");
}
Upvotes: 1
Views: 562
Reputation: 6723
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.
Upvotes: 1