How To Use Session In Asp.Net
Session state is used to store the information at the server end. Whenever we access the web application ,session id 128 ,256 or 512 bit generated.
It depends which algorithm web are using . There are some algorithms which are used to encrypt and decrypt the session data.I will discuss this algorithm in coming next tutorials. Id is generated in the form of non persistent cookie . We can used session object to store the user specific data.You have seen ,many website are compromised due to session attack.To improve the performance of websites,we can use https,ssl and other protocol to secure your web applications.Each client accessing a web application maintains a distinct session with the web server and there is also specific information associated with each of these sessions.Session state is defined in the <session state>element of the web.config file.It also stores the data specific to a user session in session variables . Different session variables are created for each user session.Session Id is transferred between the server and the client over to HTTP protocol using cookies.
Example:- When we open(login) your gmail account on your web browser then we can open all google account(orkut,google+,you tube,blogger,google analytic,adsense etc.) through session id.Because i have told that session id is transferred between the server and the client over to HTTP Protocol using cookies.
There are some steps to implement the session state variables on the as.net web applications.
Step 1:-First open your visual studio -->File-->New-->website-->select ASP.NET Empty website -->OK-->open solution explorer -->Add New Web Form -->drag and drop label,Text box and Button control on the form as shown below:-
Step 2:- Double click on Submit button -->write the following codes which are given below:-
Step 3:- No Add a New web Form -->drag and drop logout button control on the web Form as shown below:-
Step 3:- No Add a New web Form -->drag and drop logout button control on the web Form as shown below:-
Step 4:- Open the form and Write the following codes which are given below in the page load:-
Step 5:- Double click on Logout button-->Write the following codes which are given below:-
Step 6:- Once you login with the session id. that id will be use in all forms untill you click logout button.
Step 7:- when you press the logout button session id will be expired. so that will redirect you to the login page. after that you cannot able to use other forms without proper login.
No comments:
Post a Comment