locked
does not exist in the current context

    Question

  • I'm receiving the following error code "The name Cookies does not exist in the current context". I have a seperate Cookies.cs. the code below is where I receive the line error, does anyone see what I done wrong. Thanks for you time. Liam

    This is the code on the form.

    {

    if ( ( (Convert.ToBoolean(Session["UserLoggedIn"])==false) || (Session["UserLoggedIn"] == null)) && (!Cookies.CheckRememberCookie()) )

    Response.Redirect ("../"+System.Configuration.ConfigurationManager.AppSettings["loginpage"]);

    }

     

    This is the code on my cookies.cs

    //------------------------------------------------------------

    // Name: Cookies

    // Function: Static methods to manipulate cookies

    // Version: 1.0

    // Date: 02/07/05

    // Notes:

    //------------------------------------------------------------

    using System;

    using System.Web;

    using System.Web.SessionState;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.HtmlControls;

    public class Cookies

    {

    //------------------------------------------------------------

    // EnableCookie: Create 'logged in' cookie

    //------------------------------------------------------------

    public static void EnableCookie(String username)

    {

    try

    {

    HttpContext.Current.Response.Cookies["DSIPN"].Value="1";

    HttpContext.Current.Response.Cookies["DSIPN"]["username"]=username;

    HttpContext.Current.Response.Cookies["DSIPN"]["Remember"]="0";

    HttpContext.Current.Response.Cookies["DSIPN"].Expires = new DateTime(2100,01,01);

    }

    catch {}

    }

    //------------------------------------------------------------

    // KillCookie: Adjust cookie to reflect need to login again

    //------------------------------------------------------------

    public static void KillCookie()

    {

    try

    {

    HttpContext.Current.Response.Cookies["DSIPN"].Value="0";

    HttpContext.Current.Response.Cookies["DSIPN"]["Remember"]="0";

    }

    catch {}

    }

    //------------------------------------------------------------

    // GetCookie: Get username from stored cookie

    //------------------------------------------------------------

    public static String GetCookie()

    {

    try

    {

    return HttpContext.Current.Request.Cookies["DSIPN"]["username"];

    }

    catch

    {

    return null;

    }

    }

    //------------------------------------------------------------

    // CookieExists: Check to see if 'logged in' cookie exists

    //------------------------------------------------------------

    public static bool CookieExists()

    {

    try

    {

    if (HttpContext.Current.Request.Cookies["DSIPN"].Values[0]=="1")

    return true;

    else

    return false;

    }

    catch

    {

    return false;

    }

    }

    //------------------------------------------------------------

    // SetRemember: Sets a flag in the cookie so that user doesn't

    // have to login again

    //------------------------------------------------------------

    public static void SetRemember()

    {

    try

    {

    HttpContext.Current.Response.Cookies["DSIPN"]["Remember"]="1";

    }

    catch {}

    }

    //------------------------------------------------------------

    // ClearRemember: Disable remember function

    //------------------------------------------------------------

    public static void ClearRemember()

    {

    try

    {

    HttpContext.Current.Response.Cookies["DSIPN"]["Remember"]="0";

    }

    catch {}

    }

    //------------------------------------------------------------

    // CheckRememberCookie: Check to see if user doesn't need to

    // relogin

    //------------------------------------------------------------

    public static bool CheckRememberCookie()

    {

    try

    {

    if (HttpContext.Current.Request.Cookies["DSIPN"]["Remember"]=="1")

    return true;

    else

    return false;

    }

    catch

    {

    return false;

    }

    }

    }

    Wednesday, February 06, 2008 9:44 PM

Answers

  • Another VB programmer has been bagged!  The Visual Studio IDE is designed for C#.  It has many features that are just not available to VB programmers.

     

    Are you familiar with VB.NET programming? 

     

    Visual Basic started off, long before .NET, as a very laughable joke.  Microsoft took a procedure driven language, and tried to make it into an object oriented language.  BASIC existed long before there was Windows.  It has its own set of commands so that users could write procedures to perform tasks.  Code was executed by a command interpreter.  BASIC was not a compiled language.  Home computers implemented a core set of standard commands, but each vendor added their own custom commands, bells and whistles to attact buyers.

     

    Visual Basic was introduced with much hoopla, supposedly to standardize BASIC, and obsolete all of those many incarnations.  Many BASIC programmers hated it because it attempted to turn BASIC into some "phony" incarnation of C by adding a compiler and disposing of the command interpreter.  C programmers hated it even worse for the same reasons.  "How dare they?"  

     

    My point is that Visual Basic was given that same core set of commands.  They can be found today in the Microsoft.VisualBasic namespace.  Most VB programmers learn to work within these borders because they can write some pretty cool stuff. 

     

    VB.NET has resources to perform nearly every command or function that is found within the VisualBasic namespace.  Utilizing these resources instead, which are used by all of the .NET languages, is VB.NET programming in a nutshell.  C# uses these resources.

     

    What is a namespace?  The .NET Framework, like so many things associated with computers, is tree structured.  If you are familiar with a hard drive you know that there is a root directory, which contains root folders.  From these root folders you can go anywhere.  Windows Explorer can show you a tree view of all of the folders.  The .NET Framework can be viewed in very much the same way by using a tool called the Object Browser.

     

    The Object Browser shows namespaces as folders, in much the same way as Windows Explorer.  The contents of the namespace folders are shown in a pane on the right side of the object browser, again just like W.E.  Namespaces are where it all begins and ends.  What code to be executed is identified by its namespace reference.  Your program is required to provide a namespace for itself.  This name should be unique and not conflict with other names in the root namespace shared by all applications.  This uniqueness is achieved by standardizing the way in which namespaces are chosen.  The basic format is like this.

     

    Code Snippet

    namespace CompanyName.ApplicationName.ApplicationClass.ApplicationStuff

     

     

    This is basically the format that you will see throughout the Framework and the tools to use it.  This is just a start.  HOpe this helps.  Browse the Framework and you just might notice the pattern.

     

    Rudedog

    Friday, February 08, 2008 7:51 PM

All replies

  • Well that seems alright... Are the two files inside the same project? If not, try adding a reference to the project where the Cookies.cs is located. Are they in the same namespace? In the cookies, i can see no namespace block (and i think you really should add one).


    using System;

    namespace YourNamespaceHere
    {
        ....
       
        public static class Cookies
        {
           //ps. use the XML comments (just type /// before a method or class to autogenerate). These will be shown in Visual Studio
           ///<summary>
           /// Check to see if user doesn't need to relogin
           ///</summary>
           public static bool CheckRememberCookies()
           {
              ....
           }
        }
        ....
    }

    Then use the namespace in the code you need it:

    using YourNamespaceHere;
    ...
    if( !Coookies.CheckRememberCookies() )
    {
        ....
    }
    Thursday, February 07, 2008 7:51 AM
  •  

    rauhanlinnake  should be correct... If you get that error, you either didn't mark the object as public (wich you did) OR the object is in a different namespace...

    Make sure ur in the same namespace or like  rauhanlinnake  suggested, reference to it...

    Thursday, February 07, 2008 8:01 PM
  •  jannemanrobinson wrote:

     

    rauhanlinnake  should be correct... If you get that error, you either didn't mark the object as public (wich you did) OR the object is in a different namespace...

    Make sure ur in the same namespace or like  rauhanlinnake  suggested, reference to it...

     

    Whatever the cause or case, the visiblity should have been apparent---IntelliSense---when the code was written.

    Thursday, February 07, 2008 8:19 PM
  • Thanks to all of you that responed,

    I still trying to figure out my error. I'm a VB program and I've only start to learning C# about three week ago,  so I'm having a little bit on a learning curve. I sure you guys are right, I'm just haven't got it to work yet. Not sure what to ask, so let me start with namespace "name" not sure what it really looking for as a name, could you explain "Are they in the same namespace?" Thank so much for the help and your time.

    Cheer

    Liam

    Friday, February 08, 2008 6:06 PM
  • Another VB programmer has been bagged!  The Visual Studio IDE is designed for C#.  It has many features that are just not available to VB programmers.

     

    Are you familiar with VB.NET programming? 

     

    Visual Basic started off, long before .NET, as a very laughable joke.  Microsoft took a procedure driven language, and tried to make it into an object oriented language.  BASIC existed long before there was Windows.  It has its own set of commands so that users could write procedures to perform tasks.  Code was executed by a command interpreter.  BASIC was not a compiled language.  Home computers implemented a core set of standard commands, but each vendor added their own custom commands, bells and whistles to attact buyers.

     

    Visual Basic was introduced with much hoopla, supposedly to standardize BASIC, and obsolete all of those many incarnations.  Many BASIC programmers hated it because it attempted to turn BASIC into some "phony" incarnation of C by adding a compiler and disposing of the command interpreter.  C programmers hated it even worse for the same reasons.  "How dare they?"  

     

    My point is that Visual Basic was given that same core set of commands.  They can be found today in the Microsoft.VisualBasic namespace.  Most VB programmers learn to work within these borders because they can write some pretty cool stuff. 

     

    VB.NET has resources to perform nearly every command or function that is found within the VisualBasic namespace.  Utilizing these resources instead, which are used by all of the .NET languages, is VB.NET programming in a nutshell.  C# uses these resources.

     

    What is a namespace?  The .NET Framework, like so many things associated with computers, is tree structured.  If you are familiar with a hard drive you know that there is a root directory, which contains root folders.  From these root folders you can go anywhere.  Windows Explorer can show you a tree view of all of the folders.  The .NET Framework can be viewed in very much the same way by using a tool called the Object Browser.

     

    The Object Browser shows namespaces as folders, in much the same way as Windows Explorer.  The contents of the namespace folders are shown in a pane on the right side of the object browser, again just like W.E.  Namespaces are where it all begins and ends.  What code to be executed is identified by its namespace reference.  Your program is required to provide a namespace for itself.  This name should be unique and not conflict with other names in the root namespace shared by all applications.  This uniqueness is achieved by standardizing the way in which namespaces are chosen.  The basic format is like this.

     

    Code Snippet

    namespace CompanyName.ApplicationName.ApplicationClass.ApplicationStuff

     

     

    This is basically the format that you will see throughout the Framework and the tools to use it.  This is just a start.  HOpe this helps.  Browse the Framework and you just might notice the pattern.

     

    Rudedog

    Friday, February 08, 2008 7:51 PM
  •  

    Thanks Rudedog,

    That helps alot, now I know what to look for. will work on it this weekend will let you know if I resolve the issue.

    Thanks again, Cheer

    IW

    Saturday, February 09, 2008 3:13 AM