Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Type not defined - why not?!!


Message #1 by "Haydn Williams" <haydnw@y...> on Sun, 9 Mar 2003 20:25:44
Hi,

I am trying to put the following code in a Code Behind file (my first go!).
'==========================================================

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection

Public Class CheckLogin : Inherits Page

    Public txtUsername as Textbox
    Public txtPassword as Textbox
    Public chkAutoLogin as CheckBox
    Public lblLogStatus as Label

    Public Sub CheckUserLogin()

        Dim strUsername As String

        strUsername=Session("strUsername")

        If strUsername <> "Username" Then

            'Session variable exists - user is logged in.
            lblLogStatus.text = "Welcome normally logged in user" &
Session("strUsername")


        Else

        'No session variable, check for cookies
        Dim ckeExistingCookie As HttpCookie = Request.Cookies
("WWAutoLogin")

            If ckeExistingCookie Is Nothing AndAlso ckeExistingCookie.Value
= Nothing Then

                'No cookie either, user is not logged in.
                'Redirect to login.aspx
                Response.Redirect("login.aspx")

            Else
                'STORE USERNAME AND PASSWORD FROM COOKIE IN SESSION 
VARIABLE
FOR USE THIS TIME
                Session("strUsername") 
ckeExistingCookie.Values.Item("strUsername")
                Session("strForename") 
ckeExistingCookie.Values.Item("strForename")
                lblLogStatus.text = "Welcome (via autologin) " &
Session("Forename")

            End If
        End If

    End Sub

End Class
'===========================================================

When I open the web form in which I refer to the .vb file, I get the
following error:

'============================================================
Compiler Error Message: BC30002: Type 'HttpCookie' is not defined.

Source Error:


Line 27:
Line 28:         'No session variable, check for cookies
Line 29:         Dim ckeExistingCookie As HttpCookie 
Request.Cookies("WWAutoLogin")
Line 30:
Line 31:             If ckeExistingCookie Is Nothing AndAlso
ckeExistingCookie.Value = Nothing Then

Source File: C:\web\checklogin.vb    Line: 29
'============================================================

I have included "Import" statements for the HttpCookie class, so why am I
getting this error? Is there a limit on the number of "import" statments 
you
can add? For completeness, here is the code of the aspx file:

<%@ Page Inherits="CheckLogin" Src="checklogin.vb" %>
<script runat="server">

    Sub Page_Load()

    CheckLogin

    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:Label id="lblLogStatus" runat="server">Label</asp:Label>
        <!-- Insert content here -->
    </form>
</body>
</html>
'=========================================================


Many many many thanks!

Haydn

  Return to Index