Hi guys,
I am making an e-commerce website. When user want to log in he enters has username and password and that is checked against the database that is he really a registered user or not if register then make a cookie on the users pc. Now when user want to buy something when he click buy button i want to check that either he is logged in or not. Can somebody please tell me how can i check that user is logged in or not. Just tell me the logic. Or if possible provide an example. Thanks in advance.
Zeb-ur-Rehman
Loading
V S N Raju KanumuriPosted May 2, 2012, 5:55 AM
when user log in into ur application Create a session with username
for example
in login button click create session like
session["username"]=txtusername.Text;
when user click on buy
write following code
if(session["username"]!=null)
{
//write ur code
}
else
{
//go to login page
}
SenthilkumarPosted May 2, 2012, 7:07 AM
You are advised to do base page which will be base class to all the .aspx.cs file.
Because no need to write the session check logic in the every page or every event.
Have a look at the following same code base.
http://yrbyogi.wordpress.com/2010/02/04/base-page-for-detecting-session-timeout-in-asp-netc/
http://www.codeproject.com/Articles/27165/Using-a-Custom-Base-Class-for-Security-and-Session