Monday, October 4, 2010

How to Detect the browser using asp.net and c#.net

Many of times we need to detect browser type/name and its capability in asp.net
to do so below code can help you:
These properties are exposed by the HttpBrowserCapabilities object indicate inherent capabilities of the browser,
*but do not necessarily reflect current browser settings.

so using Request.Browser.Browser we can find the name of browser and using if-else/switch-case we can perform desired operation for specific browser type or we can use these to find capabilities of current browser and do operations according to supported by browser.


Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = ""
With Request.Browser
s &= "Browser Capabilities" & vbCrLf
s &= "Type = " & .Type & vbCrLf
s &= "Name = " & .Browser & vbCrLf
s &= "Version = " & .Version & vbCrLf
s &= "Major Version = " & .MajorVersion & vbCrLf
s &= "Minor Version = " & .MinorVersion & vbCrLf
s &= "Platform = " & .Platform & vbCrLf
s &= "Is Beta = " & .Beta & vbCrLf
s &= "Is Crawler = " & .Crawler & vbCrLf
s &= "Is AOL = " & .AOL & vbCrLf
s &= "Is Win16 = " & .Win16 & vbCrLf
s &= "Is Win32 = " & .Win32 & vbCrLf
s &= "Supports Frames = " & .Frames & vbCrLf
s &= "Supports Tables = " & .Tables & vbCrLf
s &= "Supports Cookies = " & .Cookies & vbCrLf
s &= "Supports VBScript = " & .VBScript & vbCrLf
s &= "Supports JavaScript = " & _
.EcmaScriptVersion.ToString() & vbCrLf
s &= "Supports Java Applets = " & .JavaApplets & vbCrLf
s &= "Supports ActiveX Controls = " & .ActiveXControls & _
vbCrLf
s &= "Supports JavaScript Version = " & _
Request.Browser("JavaScriptVersion") & vbCrLf
End With
TextBox1.Text = s
End Sub

Reference Link:http://msdn.microsoft.com/en-us/library/3yekbd5b.aspx

Solution by:Rajesh Rolen

Share This!


1 comment:

Anonymous said...

wow.. i got my issue resolved by this. thanks

Powered By Blogger · Designed By Seo Blogger Templates