Click here to Skip to main content
15,885,128 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
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
Comments
[no name] 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.

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:

http://msdn.microsoft.com/en-us/library/ff648345.aspx[^]

http://msdn.microsoft.com/en-us/library/yh26yfzy(v=vs.100).aspx[^]

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.
 
Share this answer
 
Please check Keeping an Employee object alive throughout the asp.net 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[^].

Thanks...
 
Share this answer
 
If you would want to just store the login name in the session then do the below
VB
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


VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       Response.Cache.SetCacheability(HttpCacheability.NoCache)
       Login1.Focus()
   End Sub

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

Sub validateuser()
       Try
           sqlcon = New OleDbConnection(constr)
           sqlcon.Open()
           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()
               sqlrdr.Read()
               Session("username") = Login1.UserName
               getrole = (sqlrdr.Item("role"))
               Session("userrole") = getrole
               getemail = (sqlrdr.Item("emailid"))
               Session("reqemailid") = getemail
               Response.Redirect("~\Home.aspx")
               'Response.Write("you are valid " & Session("username") & " with role " & getrole)
           Else
               'Response.Redirect("~\Default.aspx")
               'lbl_msg.Text = ("Invalid login attmept")

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900