Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Retrieving the Request.UserAgent in a class

Is it possible to retrieve the useragent in a class?

I have tried:
Dim userAgent As String = Request.UserAgent

Open in new window


And System.Web.HttpRequest etc. but it errors saying:
reference to a non-shared member requires an object reference

Can I not put this in an App_Code class?

thanks!
0
Starr Duskk
Asked:
Starr Duskk
1 Solution
 
Jitendra PatilSr.Software EngineerCommented:
hi,
The error you are getting becuase you are trying to access a non shared method OR a method of a class without its instance.

You either have to make the method Shared or use an instance of the class by creating an instance of an object.

hope this helps.
0
 
CodeCruiserCommented:
Try

Dim userAgent As String = HTTPContext.Current.Request.UserAgent
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
thanks!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now