0

I need to check browser in VB.NET, so that I can use that in an IF - ELSE condition.

Something like this:

IF(!IE){//do this }.

Can anyone please help?

2 Answers2

1

The Request object has a browser property you could reference.

    Request.Browser.Browser

Will give you the browser that you'll have to then check to see if it is IE.

You're syntax leads me to believe that this is a JavaScript or C# question. If it is JavaScript, there are plenty of libraries out there to detect browsers client side. A quick example is..

   var browser = navigator.appName;
Howie-
  • 116
  • 4
  • Thanks Howie for your reply.I am using VB.NET language. I tried `Request.Browser.Browser ='IE'` but the code is breaking at the above line and I am getting this error : `System.web.httpException:Request is not available in this context` – pourushsingh gaur Jul 30 '16 at 16:57
  • Are you using ASP.net MVC, WebForms, etc? Where is this call being made? If using MVC is it within your view or your controller method? – Howie- Jul 31 '16 at 04:16
  • Its a project on ASP.net WebForms with VB.NET as the development language. Initially when I was using `Request.Browser.Browser`I was getting error `"The Name request is not declared "` Might be this was due to namespace issue that has been solved by inheriting one template in the project. But Now the code is breaking at the above mentioned line. – pourushsingh gaur Jul 31 '16 at 05:58
1

** Dim bc As HttpBrowserCapabilities = HttpContext.Current.Request.Browser**

I have used the above statement and that worked for me! As it was not finding the httpcontext I used the above statement. Thanks