Cookie & Session In ASP.NET

ShingalaKrupa 11,959 views 20 slides Mar 13, 2014
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

No description available for this slideshow.


Slide Content

Presentation On Cookie And Session Management in ASP .NET Submitted To: Rachana Kamaliya Prepared By: Kumbhani Minaxi Limbasiya Jignasha

Index Introduction Overview of Session Session – Property/Method Session - Example Session Configuration Advantages And Disadvantages Of Session Overview Of Cookie How cookies Started? Cookie - Property Cookie – Example Advantages And Disadvantages Of Cookie Differences Between Session & Cookie References jignasha & Minaxi 1 Session & Cookie

Basic about State Management ASP.NET framework provides various ways to preserve the states at various stage. controlstate, viewstate, cookies, session, etc. These can be defined at the client side and server side state management jignasha & Minaxi 3 Session & Cookie

State Management jignasha & Minaxi 4 Session & Cookie

Overview of Session Session is server side object. It is saving your data for the session you are using the site. There is a time for which this objects stay in the memory. Session is defined in Web.Config for session state section otherwise 20 mins by default . jignasha & Minaxi 5 Fig : For every client session data store separately Session & Cookie

Session The Session is active: Till the user closes the browser or A certain period expires (20 minutes ) Every session is identified by a unique SessionID Created at first entry in the site Transmitted in a cookie by default jignasha & Minaxi 6 Session & Cookie

property jignasha & Minaxi 7 Property Description Count Gives the number of session variables which are in memory . Session ID Give you unique SessionID,which is assign to your session. TimeOut Get or Set TimeOut period. IsNew Session A Boolean value specifies whether session is new or old one. IsCookieLess A Boolean value specifies whether session is Cookless or not. Keys A collection of all keys Session & Cookie

method jignasha & Minaxi 8 Method Description Session.Remove (StrSessionName) Remove an Item from session state collection. Session.RemoveAll() Remove all Items from session collection. Session.Clear() There is no difference between clear and RemoveAll().RemoveAll() calls Clear().internally. Session & Cookie

Session - example Session Declaration: Session Retriving : Session Removing: To handle events fired when a session is started or ended we use Session_OnStart and Session_OnEnd in the Global.asax file jignasha & Minaxi 9 Session["username"] = "pesho"; string = Session["username "].ToString(); Session.Remove (“username"); or Session [“username"] = null; Session & Cookie

Session Configuration We can configure various aspects of the session mechanism Use the sessionState section in Web.config Example: jignasha & Minaxi 10 <system.web> < sessionState cookieless ="true" mode="InProc" timeout ="60" cookieName="MySite" /> </system.web> To deny/restrict access to the session <%@ Page EnableSessionState="False "%> <%@ Page EnableSessionState="ReadOnly" %> Session & Cookie

Advantages & Disadvantages Advantages: Session provide us the way of maintain user data to all over the application. session is that we can store any kind of object in it. :eg, database, dataset.. Etc Session is secure and transparent from the user. Disadvantages: Performance overhead in case of large volumes of user, because session data is stored in server memory. jignasha & Minaxi 11 Session & Cookie

Overview of Cookies Cookies are the small files that are created on the client's system or client browser memory. We can store small pieces of information in a client system and use it when needed. I t works transparently with the user. It can be easily used anywhere in your web application jignasha & Minaxi 12 Session & Cookie

How cookie started? jignasha & Minaxi 13 Session & Cookie

How cookie started?(Cont..) jignasha & Minaxi 14 Session & Cookie

property Property Description Name Specify name of cookie Value Contains value of cookie Expires Get or Set expiration Date of cookie. Expired Informs you whether cookie is expired or not. Domain Specific domain can be specified,if cookie store in specific folder. Path Allows you to set or get path of cookie to be store. jignasha & Minaxi 15 Session & Cookie

Cookie - example working with cookies, we need to use the namespace System.web. Creating a cookie that will be sent to the client Web browser : Reading a cookie received at the server : jignasha & Minaxi 16 HttpCookie cookie = new HttpCookie ("UserName", "bajivan"); Response.Cookies.Add(cookie); HttpCookie cookie = Request.Cookies["UserName"]; Session & Cookie

Advantages & Disadvantages Advantages : It's very simple to use and implement. Browser takes care of sending the data. For multiple sites with cookies, the browser automatically arranges them. Disadvantages: It stores data in simple text format, so it's not secure at all. There is a size limit for cookies data (4KB ). . Most browsers provide limits the number of cookies is 20. jignasha & Minaxi 17 Session & Cookie

1. Cookies can store only "string" data type 2. They are stored at Client side 3. Cookie is non-secure since stored in text format at client side 4. Only in few situations we can use cookies because of no security 1.Session can store any data type 2. These are stored at Server side 3. Session are secure because it is stored in binary format 4. For all condition /situations we can use sessions jignasha & Minaxi 18 Diff between cookies & session Session & Cookie

References http:// www.codeproject.com http:// en.wikipedia.org http://www.Tutorials.com jignasha & Minaxi 19 Session & Cookie

20
Tags