473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

session state with user login

dear all,
a simple quetion from still a beginner in asp.net
i have a simple webpage with username and password which is linked with
database. now when user gives
his username and password and if information is right he does move to
the required webpage. but i want
the session to start with his successful login. how to store his id in
session and start and end it when
logout is clicked.
please any small code sample that can help me.or any good relevent
article to this quetion.
thankyou in advance
nasir

Jun 28 '06 #1
1 1066
my aspx file code is as follows:-
<script runat="server">
SqlConnection objconn=new SqlConnection("user
id=sa;password=;Initial Catalog=jobsdb;Data Source=localhost;Integrated
Security=SSPI;");

SqlDataReader objDR;

bool CheckCredentials(string identity2, string Password)
{
objconn.Open();
SqlCommand objcmd=new SqlCommand("SELECT username2,password2
from tbl_login where username2=@username2",objconn);
objcmd.Parameters.Add(new SqlParameter("@username2",
SqlDbType.VarChar, 50));
objcmd.Parameters["@username2"].Value = TextBox1.Text;

objDR = objcmd.ExecuteReader();
if (!objDR.Read())
{
return false;
}
else
{
string strstoredpassword=(string)objDR["password2"];
string strgivenpassword=TextBox2.Text;

return strstoredpassword==strgivenpassword;

}

}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckCredentials(TextBox1.Text, TextBox2.Text) == true)
{
string url = "cpanelhome.aspx";
Response.Redirect(url);

}
else
{
Label1.Text = "You entered the wrong credentials!";
}
}
</script>

textbox1 is for username
textbox2 is for password

which works correctly. i want session addition in this code.
thankyou again in advance.

Jun 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Pack Fan | last post by:
I've noticed that session variables will persist on Mac IE even after all browser windows have been closed. One must quit the program to clear the session variables. This presents a security risk...
5
by: Phil Grimpo | last post by:
I have a very odd situation here. I have an administration page, where based on a users permissions, a recordset is called from the SQL server which has a list of paths to "Module Menus". Each of...
14
by: Paul Yanzick | last post by:
Hello, I am trying to develop a book tracking application for my capstone in school, and am running into a problem. The application is an ASP.Net application written in C#. The first page you...
3
by: Martin | last post by:
Hi all As my posting title suggests I'm having problems using InProc Session state in my ASP .NET app. I wrote a site for a friend which uses ADO .NET to keep track of a simple...
10
by: Jacob Anderson | last post by:
Hello, I have a web application running in two configurations: 1. On my local machine running in debug and release mode 2. On a shared, hosted, machine in release mode On my local machine,...
10
by: Li Pang | last post by:
Hi, I created a html page from which I give a link to another web site. The new site is opened in a new window. When I opened multiple windows, they all have the same SessionID. I want ot know...
11
by: Joseph Geretz | last post by:
I've been looking at two approaches for the maintenance of Session state for a Web Service application. One approach uses the old familiar Session object which I've used in the past for Web...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
0
by: pallabi sarangi | last post by:
my requirement is in a default page, for login,there r 3 fields as userid,password n state(which is in a dropdown form).By default,all the texttexts of india should be displayed.so,when a user l...
1
by: Andy | last post by:
Hi Gang I need help. I have an ASP application that in a nutshell allows data entry on a main page. The problem is I'll have users that enter some data and save it. Then they'll enter some...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.