Can someone enlighten with this login thing? Or is there any reference I can refer to through the web.
I have this Customer Module consists of Customer Listing [Contain the list of all Customer in the database] & Customer profile [Showing Individual Customer Details upon selecting which customer they wants to view] (Both are created using Visual Web Developer).
I want my user to login into this Module using their password. But, I faced with this problem as below.
Everytime, when my user go into the Main Menu, they will click on Customer Listing & straight away, the login will come in & ask for password. After my user enter successfully into the Customer listing, they will select the customer they want to see.
Upon finishing what they want to do in the Customer Details, they will click on the link to go back to the Customer Listing. but, the login will come out again & ask for the password. Is there any way to make it remember what is the password & UserID when my user click the link to go back to customer listing?
Thanks & Smile
Hi Chankl,
Let me tryand help you on this. I guess you are doing the user validation every time in the page_load function. And hence the code runs everytime you go back to the page.
You could use a session variable say "LoggedIn" and set it as equal to "Y" which you can check like the way mentioned below in page_load
If Session("LoggedIn") = "N"Then
Response.Redirect("login.aspx")
else
'there is a facility to check if the page is postbacked or not. so use that here. If it 'is postbacked then there is no need for user validation to be done. If its a fresh login then 'user validation has to be done.
If Page.IsPostBack =FalseThen
'this is the fresh login
else
'this is the code which is when postback takes place
endif
Hope this helps,
Vincent
Hmm.. Thanks Vincent...
I do not really understand about the session. Do I have to declare the "loggedIn" in the page_load?
Currently, I had created a table called Password. Inside have all the required fields so that I know who are the user have access rights to which modules (For example Customer module) in my whole software system.
Smile
chankl78
Chankl,
Sessions are not as intimidating as they might seem. You do not have to explicitly declare a session variable. Just do it like this:
//do this immediately after you authenticate the userAs Vincent pointed out, you'll probably have the !IsPostBack check in the PageLoad(). So whenever you feel that a particular zone is meant for logged in user only, you can check their status like this:
//i.e. checked the user name and password
//against the database and logged inSession["LoggedIn"] ="Y";
if (!Session["LoggedIn"] =="Y")//User not logged in, redirect somewhere elseelse//Legal logged in user, show the contentThats almost it. Have fun in sessions!
0 comments:
Post a Comment