Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Determine if user logged on? [modified]

Determine if user logged on? [modified]

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasevisual-studiodesign
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kbalias
    wrote on last edited by
    #1

    Hi I am developing an e-Commerce website using ASP.NET, Visual Studio 2003 and C#. I am allowing the user to add products to a shopping cart even if not logged in (using GUID as primary key in that case). When the user then logs on the anonymous shopping cart items are moved over to his personal shopping cart (using his customerIndex as part of primary key). I am using Forms authentication. When the logon is successful I also add info to the session content

    Session.Contents["custIndex"] = custIndex;
    Session.Contents["loginStatus"] = Enum_LoginStatus.LoggedIn;

    I want to display the anonymous shopping cart when not logged on and the personal shopping cart when logged on. I am using a helper class ShopcartAccess in the same namespace as my Web App (the ShopcartAccess class is just a normal C# class and not a webform) which has the following method:

    public static DataTable GetShopCartItems_All()
    {
    DataTable table = null;

    //IN HERE ADD CODE TO DETERMINE IF USER LOGGED IN OR ANON
    //########
    bool loggedIn = false; //temp for testing
    
    if (loggedIn == true)
    {
    	table = GetShopCartItems\_All();
    }
    else
    //use method for anonomous database access
    {
    	table = GetShopCartItems\_All\_AnonUser();
    }
    return table;
    

    }

    At the //####### in the code above I have tried using the following to determine if user logged in, but it says the type or namespace name ‘User’ can not be found.

    if (User.Identity.IsAuthenticated == true)
    {
    }

    I have also tried to access the session data, but it says the type or namespace name ‘Session’ can not be found.

    bool loginStatus = (Enum_LoginStatus) Session.Contents["loginStatus"];

    What namespaces should be added, because I have added everything that I thought could help:

    using System;
    using System.Net;
    using System.Data;
    using System.Data.Common;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.SessionState;

    Is there a better way of determining whether the user is logged on? Thanks. Kobus -- modified at 2:02 Tuesday 6th June, 2006

    Z 1 Reply Last reply
    0
    • K kbalias

      Hi I am developing an e-Commerce website using ASP.NET, Visual Studio 2003 and C#. I am allowing the user to add products to a shopping cart even if not logged in (using GUID as primary key in that case). When the user then logs on the anonymous shopping cart items are moved over to his personal shopping cart (using his customerIndex as part of primary key). I am using Forms authentication. When the logon is successful I also add info to the session content

      Session.Contents["custIndex"] = custIndex;
      Session.Contents["loginStatus"] = Enum_LoginStatus.LoggedIn;

      I want to display the anonymous shopping cart when not logged on and the personal shopping cart when logged on. I am using a helper class ShopcartAccess in the same namespace as my Web App (the ShopcartAccess class is just a normal C# class and not a webform) which has the following method:

      public static DataTable GetShopCartItems_All()
      {
      DataTable table = null;

      //IN HERE ADD CODE TO DETERMINE IF USER LOGGED IN OR ANON
      //########
      bool loggedIn = false; //temp for testing
      
      if (loggedIn == true)
      {
      	table = GetShopCartItems\_All();
      }
      else
      //use method for anonomous database access
      {
      	table = GetShopCartItems\_All\_AnonUser();
      }
      return table;
      

      }

      At the //####### in the code above I have tried using the following to determine if user logged in, but it says the type or namespace name ‘User’ can not be found.

      if (User.Identity.IsAuthenticated == true)
      {
      }

      I have also tried to access the session data, but it says the type or namespace name ‘Session’ can not be found.

      bool loginStatus = (Enum_LoginStatus) Session.Contents["loginStatus"];

      What namespaces should be added, because I have added everything that I thought could help:

      using System;
      using System.Net;
      using System.Data;
      using System.Data.Common;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Web.SessionState;

      Is there a better way of determining whether the user is logged on? Thanks. Kobus -- modified at 2:02 Tuesday 6th June, 2006

      Z Offline
      Z Offline
      Zafar Iqbal
      wrote on last edited by
      #2

      Hi, You should only add reference of System.Web and then get current request context using HttpContext.Current and then can check either session or user properties like this HttpContext.Current.User.Identity.IsAuthenticated. Hope this will solve your issue. Ghuna Singh

      K 1 Reply Last reply
      0
      • Z Zafar Iqbal

        Hi, You should only add reference of System.Web and then get current request context using HttpContext.Current and then can check either session or user properties like this HttpContext.Current.User.Identity.IsAuthenticated. Hope this will solve your issue. Ghuna Singh

        K Offline
        K Offline
        kbalias
        wrote on last edited by
        #3

        Hi Ghuna Singh Thank you for the reply. It works very well and my issue has been solved. Kobus

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups