• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • 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?

Starr Duskk
Starr Duskk
1 Solution
Jitendra PatilSr.Software EngineerCommented:
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.

Dim userAgent As String = HTTPContext.Current.Request.UserAgent
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

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