request, session and application 'not defined'?

J

James R. Davis

I am building a set of shared functions and subroutines in a vb file located
in my App_Code section of my application. The first three functions went
fine and work as expected. But I am now starting a subroutine that must
work with certain server variables and I have been stopped cold.

This is the code that frustrates me:

Sub GetConfig()
Dim strPathURL as string
strPathURL = Left (Request.ServerVariables("Path_Info"),
InStrRev(Request.ServerVariables("Path_Info"), "/"))
....
end Sub

Visual Studio states that [Name 'Request' is not declared.]

Indeed, it does the same for any statement I try that uses 'Request',
'Server', 'Session' or 'Application'.

I started the VB page with:
Imports Microsoft.VisualBasic

Imports System.Data



What more do I need to do? Thanks!!
 
S

Scott M.

The actual classes are: HTTPRequest, HTTPServer and HTTPSession. But, you
can use Request, Server and Session if you have System.Web imported in your
code. Do you?
 
J

James R. Davis

I did not have System.Web imported but when I added it there was no change
whatever in the VS diagnostic.

Further, when I tried changing the Request to HTTPRequest the diagnostic
changed to:
"Reference to a non-shared member requires an object reference"

All I am trying to do is convert some ASP code to ASP.NET as a learning
strategy. Your help is greatly appreciated.

Scott M. said:
The actual classes are: HTTPRequest, HTTPServer and HTTPSession. But, you
can use Request, Server and Session if you have System.Web imported in your
code. Do you?





James R. Davis said:
I am building a set of shared functions and subroutines in a vb file
located
in my App_Code section of my application. The first three functions went
fine and work as expected. But I am now starting a subroutine that must
work with certain server variables and I have been stopped cold.

This is the code that frustrates me:

Sub GetConfig()
Dim strPathURL as string
strPathURL = Left (Request.ServerVariables("Path_Info"),
InStrRev(Request.ServerVariables("Path_Info"), "/"))
...
end Sub

Visual Studio states that [Name 'Request' is not declared.]

Indeed, it does the same for any statement I try that uses 'Request',
'Server', 'Session' or 'Application'.

I started the VB page with:
Imports Microsoft.VisualBasic

Imports System.Data



What more do I need to do? Thanks!!
 
S

Scott M.

You do have a reference to System.Web, right?


James R. Davis said:
I did not have System.Web imported but when I added it there was no change
whatever in the VS diagnostic.

Further, when I tried changing the Request to HTTPRequest the diagnostic
changed to:
"Reference to a non-shared member requires an object reference"

All I am trying to do is convert some ASP code to ASP.NET as a learning
strategy. Your help is greatly appreciated.

Scott M. said:
The actual classes are: HTTPRequest, HTTPServer and HTTPSession. But,
you
can use Request, Server and Session if you have System.Web imported in your
code. Do you?





James R. Davis said:
I am building a set of shared functions and subroutines in a vb file
located
in my App_Code section of my application. The first three functions went
fine and work as expected. But I am now starting a subroutine that
must
work with certain server variables and I have been stopped cold.

This is the code that frustrates me:

Sub GetConfig()
Dim strPathURL as string
strPathURL = Left (Request.ServerVariables("Path_Info"),
InStrRev(Request.ServerVariables("Path_Info"), "/"))
...
end Sub

Visual Studio states that [Name 'Request' is not declared.]

Indeed, it does the same for any statement I try that uses 'Request',
'Server', 'Session' or 'Application'.

I started the VB page with:
Imports Microsoft.VisualBasic

Imports System.Data



What more do I need to do? Thanks!!
 
M

Misbah Arefin

Import System.Web and then use HttpContext.Current.Request

The static property Current on the HttpContext class can be useful whenever
the flow of control leaves the code in your Page derived web form. Using this
property you can reach out and magically grab the current Request, Response,
Session, and Application objects (and more) for the request you are servicing


--
Misbah Arefin



James R. Davis said:
I did not have System.Web imported but when I added it there was no change
whatever in the VS diagnostic.

Further, when I tried changing the Request to HTTPRequest the diagnostic
changed to:
"Reference to a non-shared member requires an object reference"

All I am trying to do is convert some ASP code to ASP.NET as a learning
strategy. Your help is greatly appreciated.

Scott M. said:
The actual classes are: HTTPRequest, HTTPServer and HTTPSession. But, you
can use Request, Server and Session if you have System.Web imported in your
code. Do you?





James R. Davis said:
I am building a set of shared functions and subroutines in a vb file
located
in my App_Code section of my application. The first three functions went
fine and work as expected. But I am now starting a subroutine that must
work with certain server variables and I have been stopped cold.

This is the code that frustrates me:

Sub GetConfig()
Dim strPathURL as string
strPathURL = Left (Request.ServerVariables("Path_Info"),
InStrRev(Request.ServerVariables("Path_Info"), "/"))
...
end Sub

Visual Studio states that [Name 'Request' is not declared.]

Indeed, it does the same for any statement I try that uses 'Request',
'Server', 'Session' or 'Application'.

I started the VB page with:
Imports Microsoft.VisualBasic

Imports System.Data



What more do I need to do? Thanks!!
 
J

Juan T. Llibre

re:
!> You do have a reference to System.Web, right?

That is not necessary.

System.Web is a built-in imported class and doesn't need a reference.
You don't need Imports Microsoft.VisualBasic nor Imports System.Data, either.

The code works fine as is...
See it working at : http://asp.net.do/test/path_info.aspx

The problem is that you can't get the ServerVariables in a "regular" sub.
You must get the ServerVariables in Page_Load...which is why you're getting the error.

Here's the code for that sample page :
-------------------------------------------------------
<%@ Page Language="VB" %>
<html>
<head>
<title>Path Info</title>
</head>
<script runat="server">
Public Sub Page_Load(Sender As System.Object, E As System.EventArgs)

path.Text = "Request.ServerVariables('Path_Info') = " & Request.ServerVariables("Path_Info")
Dim strPathURL as string
strPathURL = Left(Request.ServerVariables("Path_Info"), InStrRev(Request.ServerVariables("Path_Info"), "/"))
path2.Text = "Left(Request.ServerVariables('Path_Info'), InStrRev(Request.ServerVariables('Path_Info'), '/')) = " &
strPathURL
End Sub
</script>
<html>
<body>
<form id="Form1" runat="server">
<p>
<asp:Label id="path" runat="server" /><BR>
<asp:Label id="path2" runat="server" /><BR>
</form>
</body>
</html>
--------------







Scott M. said:
You do have a reference to System.Web, right?


James R. Davis said:
I did not have System.Web imported but when I added it there was no change
whatever in the VS diagnostic.

Further, when I tried changing the Request to HTTPRequest the diagnostic
changed to:
"Reference to a non-shared member requires an object reference"

All I am trying to do is convert some ASP code to ASP.NET as a learning
strategy. Your help is greatly appreciated.

Scott M. said:
The actual classes are: HTTPRequest, HTTPServer and HTTPSession. But, you
can use Request, Server and Session if you have System.Web imported in your
code. Do you?





I am building a set of shared functions and subroutines in a vb file
located
in my App_Code section of my application. The first three functions went
fine and work as expected. But I am now starting a subroutine that must
work with certain server variables and I have been stopped cold.

This is the code that frustrates me:

Sub GetConfig()
Dim strPathURL as string
strPathURL = Left (Request.ServerVariables("Path_Info"),
InStrRev(Request.ServerVariables("Path_Info"), "/"))
...
end Sub

Visual Studio states that [Name 'Request' is not declared.]

Indeed, it does the same for any statement I try that uses 'Request',
'Server', 'Session' or 'Application'.

I started the VB page with:
Imports Microsoft.VisualBasic

Imports System.Data

What more do I need to do? Thanks!!
 
M

Misbah Arefin

James says he gets the message that "Request" object in undefined not the
ServerVariables object... also he says that he gets this error in some class
he is making which is probably NOT derived from System.Web.Page

the solution is to use "HttpContext.Current" property to get the Request or
Session object

The static property Current on the HttpContext class can be useful whenever
the flow of control leaves the code in your Page derived web form. Using this
property you can reach out and magically grab the current Request, Response,
Session, and Application objects (and more) for the request you are servicing

--
Misbah Arefin



Juan T. Llibre said:
re:
!> You do have a reference to System.Web, right?

That is not necessary.

System.Web is a built-in imported class and doesn't need a reference.
You don't need Imports Microsoft.VisualBasic nor Imports System.Data, either.

The code works fine as is...
See it working at : http://asp.net.do/test/path_info.aspx

The problem is that you can't get the ServerVariables in a "regular" sub.
You must get the ServerVariables in Page_Load...which is why you're getting the error.

Here's the code for that sample page :
-------------------------------------------------------
<%@ Page Language="VB" %>
<html>
<head>
<title>Path Info</title>
</head>
<script runat="server">
Public Sub Page_Load(Sender As System.Object, E As System.EventArgs)

path.Text = "Request.ServerVariables('Path_Info') = " & Request.ServerVariables("Path_Info")
Dim strPathURL as string
strPathURL = Left(Request.ServerVariables("Path_Info"), InStrRev(Request.ServerVariables("Path_Info"), "/"))
path2.Text = "Left(Request.ServerVariables('Path_Info'), InStrRev(Request.ServerVariables('Path_Info'), '/')) = " &
strPathURL
End Sub
</script>
<html>
<body>
<form id="Form1" runat="server">
<p>
<asp:Label id="path" runat="server" /><BR>
<asp:Label id="path2" runat="server" /><BR>
</form>
</body>
</html>
--------------







Scott M. said:
You do have a reference to System.Web, right?


James R. Davis said:
I did not have System.Web imported but when I added it there was no change
whatever in the VS diagnostic.

Further, when I tried changing the Request to HTTPRequest the diagnostic
changed to:
"Reference to a non-shared member requires an object reference"

All I am trying to do is convert some ASP code to ASP.NET as a learning
strategy. Your help is greatly appreciated.

The actual classes are: HTTPRequest, HTTPServer and HTTPSession. But, you
can use Request, Server and Session if you have System.Web imported in
your
code. Do you?





I am building a set of shared functions and subroutines in a vb file
located
in my App_Code section of my application. The first three functions
went
fine and work as expected. But I am now starting a subroutine that must
work with certain server variables and I have been stopped cold.

This is the code that frustrates me:

Sub GetConfig()
Dim strPathURL as string
strPathURL = Left (Request.ServerVariables("Path_Info"),
InStrRev(Request.ServerVariables("Path_Info"), "/"))
...
end Sub

Visual Studio states that [Name 'Request' is not declared.]

Indeed, it does the same for any statement I try that uses 'Request',
'Server', 'Session' or 'Application'.

I started the VB page with:
Imports Microsoft.VisualBasic

Imports System.Data

What more do I need to do? Thanks!!
 
J

James R. Davis

Thank you, Juan.

You guys are very generous with your time and help. Much appreciated!

James R. Davis
 
J

Juan T. Llibre

Yes, in code-behind, you need to use HttpContext.Current.
Inline, you can do as I suggested.




Misbah Arefin said:
James says he gets the message that "Request" object in undefined not the
ServerVariables object... also he says that he gets this error in some class
he is making which is probably NOT derived from System.Web.Page

the solution is to use "HttpContext.Current" property to get the Request or
Session object

The static property Current on the HttpContext class can be useful whenever
the flow of control leaves the code in your Page derived web form. Using this
property you can reach out and magically grab the current Request, Response,
Session, and Application objects (and more) for the request you are servicing

--
Misbah Arefin



Juan T. Llibre said:
re:
!> You do have a reference to System.Web, right?

That is not necessary.

System.Web is a built-in imported class and doesn't need a reference.
You don't need Imports Microsoft.VisualBasic nor Imports System.Data, either.

The code works fine as is...
See it working at : http://asp.net.do/test/path_info.aspx

The problem is that you can't get the ServerVariables in a "regular" sub.
You must get the ServerVariables in Page_Load...which is why you're getting the error.

Here's the code for that sample page :
-------------------------------------------------------
<%@ Page Language="VB" %>
<html>
<head>
<title>Path Info</title>
</head>
<script runat="server">
Public Sub Page_Load(Sender As System.Object, E As System.EventArgs)

path.Text = "Request.ServerVariables('Path_Info') = " & Request.ServerVariables("Path_Info")
Dim strPathURL as string
strPathURL = Left(Request.ServerVariables("Path_Info"), InStrRev(Request.ServerVariables("Path_Info"), "/"))
path2.Text = "Left(Request.ServerVariables('Path_Info'), InStrRev(Request.ServerVariables('Path_Info'), '/')) = " &
strPathURL
End Sub
</script>
<html>
<body>
<form id="Form1" runat="server">
<p>
<asp:Label id="path" runat="server" /><BR>
<asp:Label id="path2" runat="server" /><BR>
</form>
</body>
</html>
--------------







Scott M. said:
You do have a reference to System.Web, right?


I did not have System.Web imported but when I added it there was no change
whatever in the VS diagnostic.

Further, when I tried changing the Request to HTTPRequest the diagnostic
changed to:
"Reference to a non-shared member requires an object reference"

All I am trying to do is convert some ASP code to ASP.NET as a learning
strategy. Your help is greatly appreciated.

The actual classes are: HTTPRequest, HTTPServer and HTTPSession. But, you
can use Request, Server and Session if you have System.Web imported in
your
code. Do you?





I am building a set of shared functions and subroutines in a vb file
located
in my App_Code section of my application. The first three functions
went
fine and work as expected. But I am now starting a subroutine that must
work with certain server variables and I have been stopped cold.

This is the code that frustrates me:

Sub GetConfig()
Dim strPathURL as string
strPathURL = Left (Request.ServerVariables("Path_Info"),
InStrRev(Request.ServerVariables("Path_Info"), "/"))
...
end Sub

Visual Studio states that [Name 'Request' is not declared.]

Indeed, it does the same for any statement I try that uses 'Request',
'Server', 'Session' or 'Application'.

I started the VB page with:
Imports Microsoft.VisualBasic

Imports System.Data

What more do I need to do? Thanks!!
 

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,598
Members
45,144
Latest member
KetoBaseReviews
Top