IPhone application are growing in the market. In this example, I will give you a simple tips that how to detect request is coming from iPhone in ASP.NET application. When ASP.NET page is requested at runtime, the information in the request header to determine what type of browser has made the request by the user agent. In this example, you will see that if the request will come from iPhone then we can do what we have required for our application and if request will not from iPhone then we don’t need to do anything.
Here’s an example
C#
protected bool isAgent()
{
if (HttpContext.Current.Request.UserAgent.ToLower().Contains("iphone"))
return true;
return false;
}
protected void Page_Load(object sender, EventArgs e)
{
if (isAgent())
{
Response.Write("iPhone Detected");// what ever you do
// you can also redirect to m.domain.com
}
}
VB.NET
Protected Function isAgent() As Boolean
If HttpContext.Current.Request.UserAgent.ToLower().Contains("iphone") Then
Return True
End If
Return False
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If isAgent() Then
' what ever you do
' you can also redirect to m.domain.com
Response.Write("iPhone Detected")
End If
End Sub
Note: If you have alternative solution, please comments here to share with us.
Output

Download
Detect-Iphone- Agent.zip (930.00 bytes)
See Live demo