0

I have created a form that includes a registration and login form in Visual Studio using the default Web Form that is already provided. So the code for someone to register and login is already provided and their inputted details are already sent to a default membership database.

What I want is once a user is logged in, they can access a members-only webpage where they enter additional details and those details can be inserted into a database I created myself. However, what I also want, is once the person enters their details into my database, they can later go back and change it.

What I would like to know is how can I get that specific user to access only their records?

I understand the use of FormView and DetailView, but they seem to display the entire database table, while I only want that specific view. I thought of trying to display the recently added records, but this causes problems because when someone else logs back into the website again and view their details, it will probably end up showing another record instead.

5
  • You need to look at a membership system - only the person with permissions would be able to view/edit/delete records. Commented Sep 21, 2014 at 0:35
  • @IrishChieftain How would I go about doing that? Commented Sep 21, 2014 at 0:46
  • @sass check my answer and tell me if something is not clear !: ) Commented Sep 21, 2014 at 0:54
  • Google is your friend - that's how I learned it :) Commented Sep 21, 2014 at 1:34
  • @sass what happend is it working now ? Commented Sep 21, 2014 at 12:08

1 Answer 1

0

You should write the user ID in the session, when he logging in. After that you can retrieve it from the session and know exact which user is log on.

Session["_USERID"] = value;

You can create property:

public Guid UserID
{
   get
      {
           if(Session["_USERID"] != null)
              return (Guid)Session["_USERID"];
      }
   set
      {
           Session["_USERID"] = value;
      }
}

This property will be set to the userID on log on and set to null on log out. It will be nice to have base class which every UI page will inherit and put this property in the base class. In this case when you open current user page, you can take this property.

Sign up to request clarification or add additional context in comments.

7 Comments

Could I replace UserID with username instead?
@sass You can store whatever you want, but you should store the PK(unique indicator) for the User Table. In this case, when you open page UserEdit (page which the user will click to edit his profile) you can make query to fetch all the user data. If you store only the name you can not retrieve always the correct information(2 guys can have same name)
@sass - If you will require that usernames be unique for all time, then you could use it. Generally it is easier and more reliable to use a key. In some environments usernames can change, e.g. email address or victims of marriage. In other cases an account may be retired but cannot be deleted due to record keeping requirements. If the records are tied to the PK then you can have a new user with the same username and not muck things up.
I apologize for being such a pain, but Guid is giving me many errors.
@sass No problem, what is the type of the PK in your data base. If it is int you will have the errors. What is the type of ID in User table.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.