Detect Browser In Code Behind ASP.NET
Certain javascript will work on certain browser only. So inorder to avoid your client from using the application which is bot supported by your application, you can filter the browser type from code behind of your web application.
Let see the example
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Let see the example
The ASPX page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
The Code Behind
protected void Page_Load(object sender, EventArgs e)
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities <br/>"
+ "Type = " + browser.Type + "<br/>"
+ "Name = " + browser.Browser + "<br/>"
+ "Version = " + browser.Version + "<br/>"
+ "Major Version = " + browser.MajorVersion + "<br/>"
+ "Minor Version = " + browser.MinorVersion + "<br/>"
+ "Platform = " + browser.Platform + "<br/>"
+ "Is Beta = " + browser.Beta + "<br/>"
+ "Is Crawler = " + browser.Crawler + "<br/>"
+ "Is AOL = " + browser.AOL + "<br/>"
+ "Is Win16 = " + browser.Win16 + "<br/>"
+ "Is Win32 = " + browser.Win32 + "<br/>"
+ "Supports Frames = " + browser.Frames + "<br/>"
+ "Supports Tables = " + browser.Tables + "<br/>"
+ "Supports Cookies = " + browser.Cookies + "<br/>"
+ "Supports VBScript = " + browser.VBScript + "<br/>"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "<br/>"
+ "Supports Java Applets = " + browser.JavaApplets + "<br/>"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "<br/>"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "<br/><br/>";
Response.Write(s);
switch (browser.Browser.ToUpper().Trim())
{
// WHY No OPERA BROWSER,because opera and chrome user agent is same,
// the browser.Browser will return Chrome value in Opera
case "CHROME": Response.Write("<b>application support your browser</b>"); break;
case "INTERNETEXPLORER": Response.Write("<b>application does not support your browser</b>"); break;
case "FIREFOX": Response.Write("<b>application support your browser</b>"); break;
case "SAFARI": Response.Write("<b>application support your browser</b>"); break;
default: break;
}
}
The Output
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)