Detect request come from mobile, tablet or desktop

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

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
}
}

Share