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
Checking Login in
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

V S N Raju KanumuriRank #8,839 · 215 reputationPosted May 2, 2012, 1:55 AM EDT
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
}
SenthilkumarRank #387 · 6.5K reputationPosted May 2, 2012, 3:07 AM EDT
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