I have a website that is written in .Net 2.0 which uses all the nice rich functionality of the web (Ajax, javascript etc..). However I have noticed that the site does not display very well on mobile devices.
So therefore I would like to create a more streamlined version of my site that is better tailored to these devices. However how do detect that the user has come to the site via a mobile device and how can i redirect them to my tailored page
You can use Request.Browser["IsMobileDevice"] to determine whether the request is from a mobile device and redirect to different version of web pages accordingly.
Zhao Ji Ma
Sincerely,
Microsoft Online Community Support
“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
This API gives detailed information of the device making the request and also has the facility to redirect user automatically to mobile specific page when request in coming from mobile device.
I have found this very useful and easy to implement in mobile website developments.
Let me know if you face any issues in usage.
Thanks
Detect Mobile DeviceDetect Mobile BrowserDetect MobileDetect Mobile InfomationDetect Mobile Settings
I don't trust this property of determining whether the request is from Mobile device or not, since once it failed to correctly identify Opera mobile on my WIndows Mobile Phone. I suspect some thing similar might happen with the i phone.
I sugguest you to use the below mentioned code to identify whether the request is from mobile device or not.
public static bool isMobileBrowser()
{
//GETS THE CURRENT USER CONTEXT
HttpContext context = HttpContext.Current;
//FIRST TRY BUILT IN ASP.NT CHECK
if (context.Request.Browser.IsMobileDevice)
{
return true;
}
//THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null)
{
return true;
}
//THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
if (context.Request.ServerVariables["HTTP_ACCEPT"] != null &&
context.Request.ServerVariables["HTTP_ACCEPT"].ToLower().Contains("wap"))
{
return true;
}
//AND FINALLY CHECK THE HTTP_USER_AGENT
//HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
{
//Create a list of all mobile types
string[] mobiles =
new[]
{
"midp", "j2me", "avant", "docomo",
"novarra", "palmos", "palmsource",
"240x320", "opwv", "chtml",
"pda", "windows ce", "mmp/",
"blackberry", "mib/", "symbian",
"wireless", "nokia", "hand", "mobi",
"phone", "cdm", "up.b", "audio",
"SIE-", "SEC-", "samsung", "HTC",
"mot-", "mitsu", "sagem", "sony"
, "alcatel", "lg", "eric", "vx",
"NEC", "philips", "mmm", "xx",
"panasonic", "sharp", "wap", "sch",
"rover", "pocket", "benq", "java",
"pt", "pg", "vox", "amoi",
"bird", "compal", "kg", "voda",
"sany", "kdd", "dbt", "sendo",
"sgh", "gradi", "jb", "dddi",
"moto", "iphone"
};
//Loop through each item in the list created above
//and check if the header contains that text
foreach (string s in mobiles)
{
if (context.Request.ServerVariables["HTTP_USER_AGENT"].
ToLower().Contains(s.ToLower()))
{
return true;
}
}
}
return false;
}
There's always a better code available. I am using this function from long time and it has never failed me.
Thanks
Anant
Mark "answer" if this post answered your question.
I agree with you that we cannot rely on property IsMobileDevice. Also the code what you have written covers most of the mobile not all, also you have to update existing .aspx page to include above code on pageload event.
I would suggest you have a look at
http://www.51degrees.mobi/Products/NETMobileAPI . It gets integrated easily in existing .aspx pages without making any change, also it covers very wide range of User Agents than what you have mentioned above. Apart from all this it also gives detailed information
of capabilities of mobile that is requesting website which can be very handy for designing mobile web pages.
the current approaches are ASP.NET Web Forms or MVC applications. Take also a look at
this forum thread about the Mobile Device Browser File from Microsoft and how to use Browser Definition Files in your mobile projects.
Remember that ASP.NET Mobile Web Forms/ASP.NET Mobile Controls are obsolete/deprecatd from .NET Framework 4.0 and that the Browser Definitions will be changed. Cf.
.NET Framework 4.0 System.Web.UI.MobileControls
BigMeat
Participant
757 Points
294 Posts
Create web site specific to mobile device, how to detect?
Oct 28, 2007 10:38 PM|LINK
Hi
I have a website that is written in .Net 2.0 which uses all the nice rich functionality of the web (Ajax, javascript etc..). However I have noticed that the site does not display very well on mobile devices.
So therefore I would like to create a more streamlined version of my site that is better tailored to these devices. However how do detect that the user has come to the site via a mobile device and how can i redirect them to my tailored page
Many thanks in advance
Zhao Ji Ma -...
All-Star
23104 Points
2380 Posts
Re: Create web site specific to mobile device, how to detect?
Oct 31, 2007 12:50 PM|LINK
Hi BigMeat,
You can use Request.Browser["IsMobileDevice"] to determine whether the request is from a mobile device and redirect to different version of web pages accordingly.
Here is the example:
Sincerely,
Microsoft Online Community Support
“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
BigMeat
Participant
757 Points
294 Posts
Re: Create web site specific to mobile device, how to detect?
Oct 31, 2007 01:07 PM|LINK
Thats great thanks for that
matrixvibe
Participant
943 Points
173 Posts
Re: Create web site specific to mobile device, how to detect?
Jul 31, 2009 11:04 AM|LINK
You can easily detect that a request is coming from mobile device using http://www.51degrees.mobi/Products/NETMobileAPI
This API gives detailed information of the device making the request and also has the facility to redirect user automatically to mobile specific page when request in coming from mobile device.
I have found this very useful and easy to implement in mobile website developments.
Let me know if you face any issues in usage.
Thanks
Detect Mobile Device Detect Mobile Browser Detect Mobile Detect Mobile Infomation Detect Mobile Settings
anantjains
Member
80 Points
15 Posts
Re: Create web site specific to mobile device, how to detect?
Sep 01, 2009 12:16 PM|LINK
I don't trust this property of determining whether the request is from Mobile device or not, since once it failed to correctly identify Opera mobile on my WIndows Mobile Phone. I suspect some thing similar might happen with the i phone.
I sugguest you to use the below mentioned code to identify whether the request is from mobile device or not.
public static bool isMobileBrowser() { //GETS THE CURRENT USER CONTEXT HttpContext context = HttpContext.Current; //FIRST TRY BUILT IN ASP.NT CHECK if (context.Request.Browser.IsMobileDevice) { return true; } //THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null) { return true; } //THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP if (context.Request.ServerVariables["HTTP_ACCEPT"] != null && context.Request.ServerVariables["HTTP_ACCEPT"].ToLower().Contains("wap")) { return true; } //AND FINALLY CHECK THE HTTP_USER_AGENT //HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null) { //Create a list of all mobile types string[] mobiles = new[] { "midp", "j2me", "avant", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows ce", "mmp/", "blackberry", "mib/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up.b", "audio", "SIE-", "SEC-", "samsung", "HTC", "mot-", "mitsu", "sagem", "sony" , "alcatel", "lg", "eric", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "dddi", "moto", "iphone" }; //Loop through each item in the list created above //and check if the header contains that text foreach (string s in mobiles) { if (context.Request.ServerVariables["HTTP_USER_AGENT"]. ToLower().Contains(s.ToLower())) { return true; } } } return false; }There's always a better code available. I am using this function from long time and it has never failed me.
Thanks
Anant
matrixvibe
Participant
943 Points
173 Posts
Re: Create web site specific to mobile device, how to detect?
Sep 02, 2009 12:57 PM|LINK
Hello Anant
I agree with you that we cannot rely on property IsMobileDevice. Also the code what you have written covers most of the mobile not all, also you have to update existing .aspx page to include above code on pageload event.
I would suggest you have a look at http://www.51degrees.mobi/Products/NETMobileAPI . It gets integrated easily in existing .aspx pages without making any change, also it covers very wide range of User Agents than what you have mentioned above. Apart from all this it also gives detailed information of capabilities of mobile that is requesting website which can be very handy for designing mobile web pages.
Thanks
Irianna
Member
8 Points
41 Posts
Re: Create web site specific to mobile device, how to detect?
Dec 15, 2009 01:36 PM|LINK
Silly question but with the code posted by Anant above, where do you put the location you want to redirect to?
matrixvibe
Participant
943 Points
173 Posts
Re: Create web site specific to mobile device, how to detect?
Dec 16, 2009 06:00 AM|LINK
Hello
You look at below article explaining details how easily you can do the detection & redirection by considering large database of mobile devices.
http://www.51degrees.mobi/Products/NETMobileAPI/MobileDeviceDetectionandRedirectionASPMVC/tabid/113/Default.aspx
Thanks
SKT_01
Participant
1930 Points
435 Posts
Re: Create web site specific to mobile device, how to detect?
Dec 16, 2009 06:56 AM|LINK
Hello,
the current approaches are ASP.NET Web Forms or MVC applications. Take also a look at this forum thread about the Mobile Device Browser File from Microsoft and how to use Browser Definition Files in your mobile projects.
Remember that ASP.NET Mobile Web Forms/ASP.NET Mobile Controls are obsolete/deprecatd from .NET Framework 4.0 and that the Browser Definitions will be changed. Cf. .NET Framework 4.0 System.Web.UI.MobileControls
amar_j
Member
76 Points
55 Posts
Re: Create web site specific to mobile device, how to detect?
Aug 13, 2010 01:52 PM|LINK
51degrees.mobi foundation the .NET open source is now available in Codeplex http://51degrees.codeplex.com/releases
Few user fiendly example are also available
- Thanks