| asp.net simple session making |
|
|
|
| Friday, 28 March 2008 17:53 | |
|
Today i learned about session making using asp.net 2008 with vb in this example, you need to create a login page and a valid session only page. steps: 1) In login.aspx page, there is one button and two textbox for user and password (later for database user checking) 2) now you create a session. syntax: session(key)=value code: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Session(TextBox1.Text) = TextBox2.Text Dim sessioncookie As HttpCookie = New HttpCookie("usersession") sessioncookie.Value = Session.SessionID Response.Cookies.Add(sessioncookie) Response.Redirect("default.aspx") End Sub explanation: you put user name in textbox1 as session key you put user password in textbox2 as session value you create cookie named usersession to store current SessionID you then move to another page (default.aspx) 3) In default.vb you create sub page load. So every time the page refresh, it will trigger the sub. code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Session.SessionID <> Request.Cookies("usersession").Value or Request.Cookies("usersession") Is Nothing Then Response.Redirect("login.aspx") End If End Sub explanation: you create a cookie checking value if the usersession cookie still hold the same value as the current SessionID. if false then you automatically redirect the page to login.aspx 4) extra note: this session method only tested in this kind environment: session name will have different sessionID every time a session expired. <sessionState cookieless="UseUri" timeout="1" regenerateExpiredSessionId="false" /> |
|
| Last Updated ( Saturday, 29 March 2008 14:06 ) |
Add your comment
Zaragoza Clouds
altiris
application
connect
create
database
deep
different
environment
error
example
express
files
freeze
install
like
management
memory
need
options
page
program
programs
protection
sandbox
sandboxie
schedule
server
session
simple
software
solution
spyware
time
used
user
using
virtual
windows
2008
Created with Zaragoza Clouds
Created with Zaragoza Clouds




