request, session and application "not defined"?

request, session and application "not defined"?

am 13.01.2008 19:44:54 von Jim

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

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

am 13.01.2008 19:54:57 von smar

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" wrote in message
news:u0qfFThVIHA.5208@TK2MSFTNGP04.phx.gbl...
>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!!
>
>

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

am 13.01.2008 20:23:21 von Jim

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." wrote in message
news:udL0pVhVIHA.5360@TK2MSFTNGP03.phx.gbl...
> 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" wrote in message
> news:u0qfFThVIHA.5208@TK2MSFTNGP04.phx.gbl...
> >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!!
> >
> >
>
>

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

am 13.01.2008 23:27:53 von smar

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


"James R. Davis" wrote in message
news:%23p6hoohVIHA.6044@TK2MSFTNGP05.phx.gbl...
>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." wrote in message
> news:udL0pVhVIHA.5360@TK2MSFTNGP03.phx.gbl...
>> 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" wrote in message
>> news:u0qfFThVIHA.5208@TK2MSFTNGP04.phx.gbl...
>> >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!!
>> >
>> >
>>
>>
>
>

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

am 13.01.2008 23:37:01 von MisbahArefin

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

> 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." wrote in message
> news:udL0pVhVIHA.5360@TK2MSFTNGP03.phx.gbl...
> > 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" wrote in message
> > news:u0qfFThVIHA.5208@TK2MSFTNGP04.phx.gbl...
> > >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!!
> > >
> > >
> >
> >
>
>
>

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

am 13.01.2008 23:57:00 von nomailreplies

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


Path Info













--------------






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." wrote in message news:%23G77oMjVIHA.6044@TK2MSFTNGP05.phx.gbl...
> You do have a reference to System.Web, right?
>
>
> "James R. Davis" wrote in message news:%23p6hoohVIHA.6044@TK2MSFTNGP05.phx.gbl...
>>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." wrote in message
>> news:udL0pVhVIHA.5360@TK2MSFTNGP03.phx.gbl...
>>> 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" wrote in message
>>> news:u0qfFThVIHA.5208@TK2MSFTNGP04.phx.gbl...
>>> >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!!

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

am 14.01.2008 00:23:02 von MisbahArefin

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" %>
>
>
> Path Info
>
>
>
>
>


>


>

>

>
>
>
> --------------
>
>
>
>
>
>
> 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." wrote in message news:%23G77oMjVIHA.6044@TK2MSFTNGP05.phx.gbl...
> > You do have a reference to System.Web, right?
> >
> >
> > "James R. Davis" wrote in message news:%23p6hoohVIHA.6044@TK2MSFTNGP05.phx.gbl...
> >>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." wrote in message
> >> news:udL0pVhVIHA.5360@TK2MSFTNGP03.phx.gbl...
> >>> 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" wrote in message
> >>> news:u0qfFThVIHA.5208@TK2MSFTNGP04.phx.gbl...
> >>> >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!!
>
>
>

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

am 14.01.2008 00:24:28 von Jim

Thank you, Juan.

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

James R. Davis

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

am 14.01.2008 00:43:43 von nomailreplies

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



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/
======================================
"Misbah Arefin" wrote in message
news:4E9ECB33-6C41-4982-98EB-F0130AFA4643@microsoft.com...
> 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" %>
>>
>>
>> Path Info
>>
>>
>>
>>
>>


>>


>>

>>

>>
>>
>>
>> --------------
>>
>>
>>
>>
>>
>>
>> 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." wrote in message news:%23G77oMjVIHA.6044@TK2MSFTNGP05.phx.gbl...
>> > You do have a reference to System.Web, right?
>> >
>> >
>> > "James R. Davis" wrote in message news:%23p6hoohVIHA.6044@TK2MSFTNGP05.phx.gbl...
>> >>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." wrote in message
>> >> news:udL0pVhVIHA.5360@TK2MSFTNGP03.phx.gbl...
>> >>> 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" wrote in message
>> >>> news:u0qfFThVIHA.5208@TK2MSFTNGP04.phx.gbl...
>> >>> >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!!
>>
>>
>>