Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi!

I need to know my website running on which devices.
it's laptop or desktop or mobile.

What I have tried:

protected override void OnInit(EventArgs e)
{
string userAgent = Request.UserAgent;
if (userAgent.Contains("BlackBerry")
|| (userAgent.Contains("iPhone") || (userAgent.Contains("Android"))))
{
//add css ref to header from code behind
HtmlLink css = new HtmlLink();
css.Href = ResolveClientUrl("~/mobile.css");
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
Page.Header.Controls.Add(css);
}
}
Posted
Updated 4-Mar-16 5:38am
Comments
Nathan Minier 23-Feb-16 8:02am    
https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent

Google. All the kids are doing it.
Sergey Alexandrovich Kryukov 23-Feb-16 10:21am    
Bad idea. The idea of the Web is to run on any client in the same way. You cannot possibly list all kinds of machines rendering your Web page.
—SA
Wombaticus 25-Feb-16 11:42am    
You need to research responsive design / responsive CSS
Valery Possoz 25-Feb-16 17:37pm    
You don't, it's a bad idea and it does not work well.
To learn about responsive design have a look at bootstrap for example.

Use google analytics, that what everyone else uses.
 
Share this answer
 
Hi

I think you can use in asp.net this variable to know is a Desktop or mobile web browser

C#
Request.Browser.IsMobileDevice
True if a mobile.
C#
Request.Browser.Platform
Name of platform in windows is "WinNT"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900