Re: error: name 'Request' is not declared

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Feb 20, 3:39 pm, "Vincent" <vi,@sd.cv> wrote:
Hi,

The startpage of the application creates a httpCookie:

Dim check As New HttpCookie("ok")
check.Value = "yes"
Response.Cookies.Add(check)

Each page of the application receives that cookie in order to check whether
the user is passed by that startpage:

Dim check As HttpCookie
check = Request.Cookies("ok")
if check.Value="yes" then
....
else
'exit
...
end if

What i want is to put those lines in a shared sub and so avoiding to have to
put those lines in each page. Each page gets then this: check.checkcookies()

So I put the code in a class:

Public Class check
Public Shared Sub checkcookies()
Dim check As HttpCookie
check = Request.Cookies("ok")
if check.Value="yes" then
....
else
'exit
...
end if
End Sub
End Class

But i have the error: name 'Request' is not declared.

Thanks for help.
Vincent

The "check" class will not know what the Request of the page is, if
you want to be able to use the shared method you will need to pass the
request object to the method:

//////////////////////
Public Class check
Public Shared Sub checkcookies(request As Request)
........
End Sub
End Class
//////////////////////

A better pattern might be to create a base page object that has the
check code in it. Then all the pages that you want to use the check
for will just need to inherit that base page. It's a cleaner and more
object orientated approach in my opinion.

Thanks,

Seth Rowe [MVP]
.



Relevant Pages

  • Re: error: name Request is not declared
    ... The startpage of the application creates a httpCookie: ... Dim check As New HttpCookie ... name 'Request' is not declared. ... Public Shared Sub checkcookies ...
    (microsoft.public.dotnet.languages.vb)
  • error: name Request is not declared
    ... The startpage of the application creates a httpCookie: ... Dim check As New HttpCookie ... Public Shared Sub checkcookies() ...
    (microsoft.public.dotnet.languages.vb)
  • Re: On Error GoTo is not working
    ... Dim strRequestID As String ... Dim strMessage As String ... MsgBox "Required fields for this form are: Request ID, Date, Name, ...
    (microsoft.public.access.formscoding)
  • Re: On Error GoTo is not working
    ... Dim strRequestID As String ... Dim strMessage As String ... MsgBox "Required fields for this form are: Request ID, Date, Name, ...
    (microsoft.public.access.formscoding)
  • Re: how can I change this get code to post code
    ... In a get I didn't write anything but in a post I have to so that is why the streamwriter is required. ... Now when we run rep=req.getresponsethe postdata that was put in the web request req is now being sent to the jsp page and it's reply is being stored in rep. ... dim strcontent as string ... Dim strContent As String ...
    (microsoft.public.dotnet.languages.vb)