locked
User logged in RRS feed

  • Question

  • User-339051678 posted

    Hi

    I've created a ASP.NET Web Application (MVC) and created a new User.

    How does I know which user is logged in? The goal is that a user can create, modify, delete his records only. He can see everything.

    Does anyone has an idea?

    Thanks Miller

    Friday, March 20, 2015 11:40 AM

Answers

  • User1765474751 posted

    Hi Mickmiller, i think i can understand what you wanna say..

    Mickmiller

     

    I mean to set the flag on the logged in users 


    You mean if any user is logged in for at least one time that user should be marked with a flag or notation or any thing etc...???

    Am i right..???


    if Yes...!!!
    Then,

    Yes its possible but it needs a little complex logic.

    You should to Creat User table with the an extra attribute of name LoggedIn which may contains "Yes" Or "No"

    when User Registration is being done , that time you should not to allow user to enter data for attribute LoggedIn, you can hide this from your view as you know.

    All of user data should be Inserted in table which was submitted by the user except of this attribute LoggedIn,

    By Default you will assign "No" to LoggedIn attribute in your controller by self and save it.

    Now at the time of Logging In of User you must need to check user in your table as we usually do.

    if user is Registered and have the same username, password etc in table so to assign a session and give access to his profile,

    When User is found in the table with its username and password that time you should 
    to run an Update Query at that table on its specific
    row and to Update Loggedin attribute from "NO" to "Yes" NOte: This updation will be done at behind of the view.

    Now if you wanna check list of all Registered Users you can Distinguish between that users which are LoggedIn and which are not yet by using if else logic

    If LoggedIn is == "Yes" then ..show User with a specific flag or Mark or show whatever you want to show with it....
    If LoggedIn is == "NO" then leave it as it is Or you can show it by any other mark so that loggedIn users
    have their own mark of identification and those which are not LoggedInn will have there own mark of identification. 

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

    And also if you wants Users that how many times has he loggedIn. You can add one More attribute to the table "No_OfLoggedIn" which can be increment Each time when user logged In.
    Same way all of updation will be done at behind of view

    Best Regards..!!!
    Riaz khan

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 23, 2015 8:22 AM

All replies

  • User2103319870 posted

    Mickmiller

    How does I know which user is logged in?

    If you are using windows authentication, then to get the details of user who is logged in Currently you can use the below code

    string username = User.Identity.Name;

    Friday, March 20, 2015 11:47 AM
  • User-339051678 posted

    Hi

    I mean the webuser who is logged in (Hello testuser@asp.net!). This user is stored in the database.

    A possability could be to set a flag in the database: loggedIn = true.

    What do you mean to this proposal?

    thanks Miller

    Friday, March 20, 2015 3:51 PM
  • User2103319870 posted

    A possability could be to set a flag in the database: loggedIn = true.

    What do you mean to this proposal?

    IMHO I wont vote for this solution. Consider a scenario where you have multiple users logged into your site at same time. Then for all these users you will have the flag set as true. From this how we will fetch the logged in user details for each session.

    Friday, March 20, 2015 3:59 PM
  • User-339051678 posted

    hi

    I mean to set the flag on the logged in users not in general.

    Saturday, March 21, 2015 12:20 PM
  • User1644755831 posted

    Hello Mickmiller,

    If you are using asp.net identity the you get the username using

    string username = User.Identity.GetUserName();

    You will need to use following namespace.

    using Microsoft.AspNet.Identity;

    Hope this helps.

    With Regards,

    Krunal Parekh

    Monday, March 23, 2015 2:12 AM
  • User1765474751 posted

    Hi Mickmiller, i think i can understand what you wanna say..

    Mickmiller

     

    I mean to set the flag on the logged in users 


    You mean if any user is logged in for at least one time that user should be marked with a flag or notation or any thing etc...???

    Am i right..???


    if Yes...!!!
    Then,

    Yes its possible but it needs a little complex logic.

    You should to Creat User table with the an extra attribute of name LoggedIn which may contains "Yes" Or "No"

    when User Registration is being done , that time you should not to allow user to enter data for attribute LoggedIn, you can hide this from your view as you know.

    All of user data should be Inserted in table which was submitted by the user except of this attribute LoggedIn,

    By Default you will assign "No" to LoggedIn attribute in your controller by self and save it.

    Now at the time of Logging In of User you must need to check user in your table as we usually do.

    if user is Registered and have the same username, password etc in table so to assign a session and give access to his profile,

    When User is found in the table with its username and password that time you should 
    to run an Update Query at that table on its specific
    row and to Update Loggedin attribute from "NO" to "Yes" NOte: This updation will be done at behind of the view.

    Now if you wanna check list of all Registered Users you can Distinguish between that users which are LoggedIn and which are not yet by using if else logic

    If LoggedIn is == "Yes" then ..show User with a specific flag or Mark or show whatever you want to show with it....
    If LoggedIn is == "NO" then leave it as it is Or you can show it by any other mark so that loggedIn users
    have their own mark of identification and those which are not LoggedInn will have there own mark of identification. 

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

    And also if you wants Users that how many times has he loggedIn. You can add one More attribute to the table "No_OfLoggedIn" which can be increment Each time when user logged In.
    Same way all of updation will be done at behind of view

    Best Regards..!!!
    Riaz khan

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 23, 2015 8:22 AM