How can I detect the device from which my website is accessed? - asp.net

I have .NET website that is mainly built for desktop browsers but I'm currently making a mobile version of it. What I'm trying to do is load the website according to the device on which it is accessed by the user. Is there a way that I can get information about the user's device when they request the site?
Regards,
Sumit.

As suggested by others you can use the System.Web.HttpBrowserCapabilities class accessible through Request.Browser however without updated browser definition files the information is completely worthless.
For example, if you use Request.Browser.IsMobileDevice this should give you what you want, but is based on a set of very dated regular expressions in your .NET framework folders in Windows.
You can see the kind of problems that can be encountered on a (currently unanswered and unloved) post here on Stack Overflow.
If you do not plan on keeping the browser definition files up to date (which is no small task) then quite simply do not go down this route.
If you simply want to know whether the user is viewing on a mobile device then here are a few options:
Detect Mobile Browsers
51Degrees.mobi
WURFL
User Agent Info
Some of those are free, some aren't and if you are really only interested in whether it is a mobile device, my recommendation would be to use Detect Mobile Browsers.

Take a look at the HttpBrowserCapabilities class.
Enables the server to gather information on the capabilities of the browser that is running on the client.
This is actually exposed on the Request property of the Page object - in an ASP.NET page you can do the following:
var browserCap = this.Request.Browser;

You can examine the HttpRequest.Browser property - MSDN link.

If you are looking for something more low level: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.useragent(v=vs.90).aspx

A commercial alernative is BrowserHawk

Related

Trusted Web Activity & Bubblewrap forcing the render engine (Chromium/firefox/geko)

Is there a way with bubblewrap when building a TWA to force the #custom-tabs engine that is used? Ie at the moment if a user has their default browser set as Firefox the TWA installed will use the Firefox/gecko implementation...
I'd rather force TWA to use chromium #custom-tabs due to additional APIs available and CSS handling..
Additionally testing is far easier with one engine than two.
Thanks
Bubblewrap doesn't provide an option to always use a specific provider. That is by design, for two reasons:
it's not possible to guarantee that a given browser will be installed for all users.
favour the user's browser choice.
It is possible to modify the app directly to get this behaviour, but due to the reasons above, not recommended.

Hp Touchpad Browser ASP.NET thinks that cookies disabled

Just bought a cheap defunct hp touchpad. I notice that when I browse to my asp.net web app the url returns session id. The touchpad has cookies enabled and my web.config contains no mention of 'cookieless' which I would have thought would default to "false". IOW This should not be happening. And I have not seen this behavior with any other Browsers I have used on this particular web app.
Is there some other reason that would result in the session id being embedded in the url for this browser?
Edit
Ok i just noticed that, although cookies are enabled for the browser (and visits to 'Browser capability' online sites back this up), ASP.NET's HttpBrowserCapabilities.Cookies is set to false.
Sounds like the default ASP.NET browser capabilities detection doesn't handle WebOS browser.
Microsoft has given up updating the browser capabilities actually, but you can have similar functionality from Wireless Universal Resource File (WURFL) project:
http://wurfl.sourceforge.net/dotNet/ (powered with sample code)
The current officially recommended way to make use of this data is through a library called 51Degrees.mobi http://51degrees.codeplex.com/
I say officially recommended as per:
http://www.asp.net/learn/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application
which is one of the most complete references for dealing with mobile devices in general, and is part of:
http://www.asp.net/mobile
Check it for more documentation.
There are other alternatives as well like:
http://blog.mobileesp.com/?page_id=53
which gives you general classes of devices. You'd be checking for WebOSTablet instead of cookies support, so, it's helpful more in device specific optimizations than for general capabilities detection.
But you probably want to try the WURFL project API or the 51Degree.mobi API for the detection.

What is meaning of ACTIVE in ASP.NET(ACTIVE Server Pages)?

What is meaning of ACTIVE in ASP.NET(ACTIVE Server Pages)?
Can you please provide an explanation on why it is named 'ACTIVE'?
Active was one of Microsoft's favorite words when the original ASP first came out. Other items like ActiveDirectory, ActiveSync, and ActiveX Data Objects also came out of this mid-late 90's "Active" era.
It had more to do with marketing than anything IMO.
EDIT: And ActiveX and Active Accessibility...
This is referring to the fact that the pages are running ActiveX scripts and server controls, from here:
Microsoft® Active Server Pages (ASP)
is the server-side execution
environment in Microsoft Internet
Information Server (IIS) 3.0 that
enables you to run ActiveX™ scripts
and ActiveX server components on the
server. By combining scripts and
components, developers can create
dynamic content and powerful Web-based
applications easily.
It is due to you are Actively Running Scripts.
Developing functionality in ASP websites is enabled by the active scripting engine's support of the Component Object Model (COM), with each object providing a related group of frequently-used functions and data attributes.
See here.
This is purely my opinion (and not necessarily the fact) but I would assume because unlike an HTML page it's not static. It's just another word for Dynamic.
Edit: David's post offers a better actual description of it.
i think it might have to do with ActiveX ... see here -> http://en.wikipedia.org/wiki/Active_Scripting
An active web document consists of a computer program(JS,applet etc.) that the server sends to the browser and that the browser must run locally. • When it runs, the active document program can interact with the user and change the display continuously.
It means that the pages have behavior... that they act to generate the result the user sees, rather than simply being a copy of the document the user ends up seeing.

What is the best method for storing viewstate in an ASP.Net mobile web application?

I'm curious what techniques you find to be the best for storage and maintaining of viewstate with respect to an ASP.Net application running within a mobile web browser (i.e. Treo with Windows Mobile, or Blackberry Curve web browser).
If you use the mobile controls, the view state can actually be stored in the session instead so it doesn't eat bandwidth.
See this link http://msdn.microsoft.com/en-us/library/cteh3e77.aspx for more about mobile controls and maintaining state.
Hope this helps.
Some of the mobile controls still store settings in ways that older phones may not support. If you are targeting older mobile phones, you should either change your session settings to cookieless or start using the HiddenVariables collection instead (which older phones can use). We used hiddenvariables since changing our whole site over to cookieless was not an option. However, hiddenvariables can only be strings so you will need to be ready to serialize objects into hidden fields as strings, just like viewstate does.

Mobile device is detected as non mobile device

I've included a mobile web form in my asp.net project, I thought that it could/should be seen just for my mobile users but I realize that it can also be seen from any browser, I don't see problem there cause I could diff the access using HttpBrowserCapabilities.IsMobileDevice=true and transferring to the appropiate aspx page, but it results that when I access to the web form from my mobile device it is identified as IsMobileDevice = false and sends me to another page.
How could it be possible that?
The mobile device runs Pocket PC 2003.
IMHO: The value of HttpContext.Current.Request.Headers("User-Agent") is a much safer bet as it actually indicates the browser that is making the request, and not the type of device per-se.
I've learnt from experience that if a smart phone makes a request through a third-party browser to your service, more-often-than-not any sort of "what type of device are you" test (HttpCapabilitiesBase.IsMobileDevice and/or HttpContext.Current.Request.Browser.IsMobileDevice) will fail.
Unfortunately though, short of a big list of allowed user-agents (or disallowed user-agents for that matter), you'll just have to make sure it doesn't start with Mozilla, iPhone or Opera before you render the page...
It's a hard arena to play in.
Good luck.
Some are not recognized, because the UserAgent has been messed with or a new browser is being used. Such as Opera Mobile 9.5. To fix this you need to create a Browser (*.browser) file specifically for defining this. I had to do it for the new Mozilla based UserAgent that is being sent from Google.
I think you should use other DDR better than Microsoft Browser Capabilities. I´m using http://wurfl.sourceforge.net>WURFL, it is open source and maybe it is more extended and updated. There is other commercial DDRs like DeviceAtlas.
There is many some .net libraries but i´m using Marg.Wurfl. It allows to rendering web mobile page using wurfl capabilities.

Resources