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

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";
Updated 4-Mar-16 5:38am
Nathan Minier 23-Feb-16 8:02am

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

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

True if a mobile.
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