login - Display logged in user asp.net -
i have made little custom log-in page in asp.net, see code:
dim strcon string = configurationmanager.connectionstrings("goed").connectionstring 'create connection string , sql statement dim strselect string = "select count(*) tbl_login gebruiker = @gebruiker , wachtwoord = @wachtwoord" dim con new sqlconnection(strcon) dim cmd new sqlcommand() cmd.connection = con cmd.commandtype = commandtype.text cmd.commandtext = strselect dim gebruiker new sqlparameter("@gebruiker", _ sqldbtype.varchar) gebruiker.value = txtus.text.trim().tostring() cmd.parameters.add(gebruiker) dim wachtwoord new sqlparameter("@wachtwoord", _ sqldbtype.varchar) wachtwoord.value = txtpw.text.trim().tostring() cmd.parameters.add(wachtwoord) con.open() dim result integer = directcast(cmd.executescalar(), int32) con.close() if result >= 1 response.redirect("default.aspx") else lblmsg.text = "gebruikers naam en of wachtwoord kloppen niet" end if end sub
as can see directs default.aspx.
on defaults.aspx page have header. in header want small label sdhow logged in user like: hello [user] how can done?
using sessions:
while directing new page (at login.aspx-in button's onclick event)
session["valuename"]=value;
on new page( default.aspx in case) use:
label1.text=session["valuename"].tostring();
or can use cookies well:
create:
response.cookies("userinfo")("username") = "diederikeen" response.cookies("userinfo")("lastvisit") = datetime.now.tostring() response.cookies("userinfo").expires = datetime.now.adddays(1)
reading:
if not request.cookies("username") nothing label1.text = server.htmlencode(request.cookies("username").value) end if if not request.cookies("username") nothing dim acookie httpcookie = request.cookies("username") label1.text = server.htmlencode(acookie.value) end if
more here: