19 February 2014

Detect the browser using ASP.NET and C#



<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="BrowserDetails" runat="server">
    </div>
    </form>
</body>
</html>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{

  
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HttpBrowserCapabilities browser = Request.Browser;
            string Content = "Browser Family : "+ browser.Browser;
            Content += "</br>";
            Content += "Browser Type : " + browser.Type;
            Content += "</br>";
            Content += "Supports Javascript : " + browser.EcmaScriptVersion.ToString();
            Content += "</br>";
            Content += "Javascript Version : " + browser.JScriptVersion.ToString();
            Content += "</br>";
            Content += "Is Browser Supports Cookies : " + browser.Cookies.ToString();
            Content += "</br>";
            Content += "Is Browser is a Search engine web crawler? : " + browser.Crawler.ToString();
            Content += "</br>";
            Content += "Is this Mobile Browser? : " + browser.IsMobileDevice.ToString();
            Content += "</br>";
            Content += "Is ActiveX Control Enabled? : " + browser.ActiveXControls.ToString();
            Content += "</br>";
            Content += "Platform : " + browser.Platform.ToString();
            Content += "</br>";
            this.BrowserDetails.InnerHtml = Content;
        }
    }
}

No comments:

Post a Comment