Login logout a username

How to display username upon successfully logged in and cannot go back

Page 1 of 1

1 Replies - 4459 Views - Last Post: 09 February 2009 - 08:15 AM Rate Topic: -----

#1 mbiol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-February 09

Login logout a username

Posted 09 February 2009 - 01:37 AM

May i know How to display username upon successfully logged in and cannot go back to page upon successfully logged out in asp.net? thank you very much in advance!
Is This A Good Question/Topic? 0
  • +

Replies To: Login logout a username

#2 lemonacode  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 02-February 09

Re: Login logout a username

Posted 09 February 2009 - 08:15 AM

Hello welcome to dream.in.code, to achieve this you would need to drag 2 asp.net buttons and a label onto your page, name them appropriately, so for example (btnLogin, btnLogout, lblUser) 'btn' for button 'lbl' for label
(NOTE: btnLogout.visible = false)
Drag a text box onto your page, name it txtUser and then double click on the btnLogin button to edit the code, create a session and put an if statement in the button that determines whether the session is valid or not for example;

txtUser.Text = lblUser.text
lblUser.Text = Session("user")
If(Session("user") == "") Then
Response.Write("You cannot login")
Else
//EDIT: txtUser.visible = false
txtUser.visible = false
lblUser.visible = false
//btnLogout would need to be valid here and btnLogin would need to be false
btnLogout.visible = true
btnLogin.visible = false
Response.Write("Welcome " & Session("user"))

End if

Then all you need to do is double click btnLogout to edit the code and just put Session("user") = ""(which sets the sessions to nothing) then Session.Abandon, then set what you made false to true and run your application. This is just the basic concept of logging in and out with asp.net.
Have a look at putting this if statement in the page_load sub of the page you want to protect and set the content you dont want them to see to false until they have logged in and it should work :)

*Also this may not be the most secure way, but its very basic and easy to learn the concept of user authentication.

This post has been edited by lemonacode: 09 February 2009 - 08:19 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1