Detect browser language and other information in ASP.NET

If you just want to detect browser language you can use this

  CultureInfo ci;  
       if (userLanguages.Count() > 0)  
       {  
         try  
         {  
           ci = new CultureInfo(userLanguages[0]);  
         }  
         catch (CultureNotFoundException)  
         {  
           ci = CultureInfo.InvariantCulture;  
         }  
       }  
       else  
       {  
         ci = CultureInfo.InvariantCulture;  
       }  

if you want to get more details then use this


   string browser = HttpContext.Request.Browser.Browser;  
       string version = HttpContext.Request.Browser.Version;  
       string type = HttpContext.Request.Browser.Type;  
       string platform = HttpContext.Request.Browser.Platform;  
       string userAgent = HttpContext.Request.UserAgent;  
       string[] userLang = HttpContext.Request.UserLanguages;  
       var userLanguages = Request.UserLanguages;  


For MVC use this in your Home controller action.



Popular posts from this blog

WPF Crystal Report Viewer Using SAP

ASP.NET MVC razor SAP Crystal report