Request.ServerVariables In Seperate Class file?

  • Thread starter Jason Hawthorne
  • Start date
J

Jason Hawthorne

I am trying to get this code to work in a class file that I use in all
of my pages.


Public Shared Function Check_Site() As String

Dim arr() As String
Dim coll As NameValueCollection

coll = Request.ServerVariables
arr = coll.GetValues("SERVER_NAME")

Select Case arr(0)
Case "site1.domain.com"
Check_Site = "THISSITE"
Case "site2.domain.com"
Check_Site = "THATSITE"
End Select

End Function

Currently the error I get is "Name 'request' is not declared" in the
class file.

But if I move the code to the aspx file the error goes away. The only
problem is I need to use this code in a lot of pages, so it needs to be
in a class file in a public shared function. How can I go about doing
this?
 
P

Peter Rilling

You cannot directly access the Request object because it is a property of
the Page class and therefore needs to be referenced from your page.

You can, however, pass a reference to the page class into your function and
then you can access it.

Don't forget that you will also have to add the necessary references to the
System.Web namespace if this class is not in your web project.
 
J

Juan T. Llibre

If you're doing this in code ( not inline ), use :

coll = HttpContext.Current.Request.ServerVariables
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,171
Latest member
VinayKumar Nevatia__
Top