CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Home > CodeDigest >  
Technologies
 


Get Client BrowserName, Version and Operating System name in ASP.Net Codebehind
Submitted By Bala Murugan
On 5/24/2010 8:30:51 AM
Tags: ASP.Net,CodeDigest  

Get Client BrowserName, Version and Operating System name in ASP.Net Codebehind

 

At times, we need to get the client informations like browser, version and the operating system in codebehind file in Asp.Net.  Every time when a browser makes a request to a website it contructs the web request by populating all the client related information like browser information, type of OS used, type of client(mobile or a computer, or any other smart devices), etc in the header for the webserver to do the processing.

 

The web request once received by webserver will be passed on to the ASP.Net runtime in our case for further processing. The ASP.Net runtime will contruct a context object(HttpContext) which will have all the information about the client's request. This context object exposes a Request object which has request specific information.

The Request object has a property called Browser which will help us to fetch the browser related information.


This small code snippet will help us to fetch the client Broswer name, version and operating system the user is accessing your page. Refer below,

 

    protected void Page_Load(object sender, EventArgs e)

    {

        HttpBrowserCapabilities browse = Request.Browser;

        Response.Write("Your Browser name: " + browse.Browser);

        Response.Write("<BR>");

        Response.Write("Your Browser version: " + browse.Version);

        Response.Write("<BR>");

        Response.Write("Your Operating System: " + browse.Platform);

       

    }

 

The Browser property will provide more information in additional to the above.

 

You can see the other properties through the intellisense when you type Request.Browser in your visual studio.

Recent Codes
  • View All Codes..