Click here to Skip to main content
13,401,763 members (50,562 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hi all,
i am working on a application for employee details. if an employee login to his site, that person username and password should be maintain in session for all the pages, how can it be done please help me.
Posted 24-Jan-13 19:52pm
pranathis012 25-Jan-13 1:23am
please be elaborate your question....
Angel riti 25-Jan-13 1:37am
so u want maintain the username,password in a session and based on that credentials u want check the details of the person and if any updates u want to do also it should be help ful right.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Dear Angelina,

Looking at your question I believe you haven't completed such task previously. User management is important part of your application, and must be implemented veruy carefully, as system hack might cost a lot.

ASP.NET starting from version 2 allows using ready to use membership providers:[^][^]

Following these guides and approaches will make your application design more robust.
Demos also could be found on asides of articles above.

I believe there several articles on a codeproject too.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Please check Keeping an Employee object alive throughout the app[^].

And if you want to explore more for session, then go for the below articles.
1. Exploring Session in ASP.NET[^].
2. Understanding Session Management Techniques in ASP.NET[^].

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

If you would want to just store the login name in the session then do the below
Session("username") = Login1.UserName

if you would want to check the login name against a database
Drag a drop a Login control onto the page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   End Sub

   Protected Sub Login1_LoggedIn(sender As Object, e As System.EventArgs) Handles Login1.LoggedIn
       ' Session("username") = Login1.UserName
   End Sub

Sub validateuser()
           sqlcon = New OleDbConnection(constr)
           sqlcmd = New OleDbCommand("SELECT COUNT(*) FROM userrole WHERE username = '" + Login1.UserName + "'" AND username = '" + Login1.Password + "'", sqlcon)
           retval = sqlcmd.ExecuteScalar
           If retval = 1 Then
               sqlcmd = New OleDbCommand("SELECT role, emailid FROM userrole WHERE username = '" + Login1.UserName + "'", sqlcon)
               sqlrdr = sqlcmd.ExecuteReader()
               Session("username") = Login1.UserName
               getrole = (sqlrdr.Item("role"))
               Session("userrole") = getrole
               getemail = (sqlrdr.Item("emailid"))
               Session("reqemailid") = getemail
               'Response.Write("you are valid " & Session("username") & " with role " & getrole)
               'lbl_msg.Text = ("Invalid login attmept")

           End If
       Catch ex As Exception
           lbl_msg.Text = ex.Message.ToString
       End Try
   End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180218.2 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100