Re: request, session and application 'not defined'?



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" wrote:

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>
--------------






Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Scott M." <smar@xxxxxxxxxxxxx> wrote in message news:%23G77oMjVIHA.6044@xxxxxxxxxxxxxxxxxxxxxxx
You do have a reference to System.Web, right?


"James R. Davis" <Jim@xxxxxxxxxxx> wrote in message news:%23p6hoohVIHA.6044@xxxxxxxxxxxxxxxxxxxxxxx
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." <smar@xxxxxxxxxxxxx> wrote in message
news:udL0pVhVIHA.5360@xxxxxxxxxxxxxxxxxxxxxxx
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" <Jim@xxxxxxxxxxx> wrote in message
news:u0qfFThVIHA.5208@xxxxxxxxxxxxxxxxxxxxxxx
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!!



.



Relevant Pages

  • Re: request, session and application not defined?
    ... when I tried changing the Request to HTTPRequest the diagnostic ... work with certain server variables and I have been stopped cold. ... Sub GetConfig() ... Imports System.Data ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: request, session and application not defined?
    ... Juan T. Llibre, asp.net MVP ... property you can reach out and magically grab the current Request, Response, ... You don't need Imports Microsoft.VisualBasic nor Imports System.Data, ... The problem is that you can't get the ServerVariables in a "regular" sub. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: request.servervariables collection
    ... As for those ServerVariables you mentioned, in ASP.NET the Buildin objects ... Request or the HttpContext.Current's members have encapsulated some of ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Chat client/server print failed
    ... is the print statement in the send_msg_all sub. ... leave the server running for testing purposes. ... # This would be the end of file, so close the client ... # just read means there is a complete request waiting ...
    (comp.lang.perl.misc)
  • Chat client/server print failed
    ... This is a chat client wrote in perl Gtk2. ... is the print statement in the send_msg_all sub. ... leave the server running for testing purposes. ... # just read means there is a complete request waiting ...
    (comp.lang.perl.misc)