473,385 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Request.ServerVariables In Seperate Class file?

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?
Dec 2 '05 #1
3 1893
If you're doing this in code ( not inline ), use :

coll = HttpContext.Current.Request.ServerVariables

Juan T. Llibre
ASP.NET.FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================

"Jason Hawthorne" <po****@nospam.postalias> wrote in message
news:MP************************@msnews.microsoft.c om...
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?

Dec 2 '05 #2
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.

"Jason Hawthorne" <po****@nospam.postalias> wrote in message
news:MP************************@msnews.microsoft.c om...
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?

Dec 2 '05 #3
you need to access it via the session context.

http://msdn.microsoft.com/library/de...sp01242002.asp

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Jason Hawthorne" <po****@nospam.postalias> wrote in message
news:MP************************@msnews.microsoft.c om...
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?

Dec 2 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jgamble | last post by:
Hi, Here's a question for you all. Under "classic" ASP any ASP page could have any number of #Include files. Using #Include files I could have functions which were common to my whole site and...
10
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of...
1
by: Oren | last post by:
Hello, I tried to get UserName and Domain by doing: System.Collections.Specialized.NameValueCollection var = Request.ServerVariables; string sLogonUserArr = var.ToString().Split('\\'); It's...
8
by: samaelsh | last post by:
Hi guys! I`ve got an ASP web site that worked perfectly on a virtual server. I had to reinstall it on my computer (win XP sp2, IIS 5.1). I changed all the routes, database connection string, etc....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.