Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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
Comments
Angel riti at 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
good
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:
 
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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...
Rate this: bad
good
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
       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
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2014
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