Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are...
-
Upload
simone-hicken -
Category
Documents
-
view
213 -
download
0
Transcript of Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are...
![Page 1: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/1.jpg)
State ManagementNot like the State of Virginia
![Page 2: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/2.jpg)
What is State in ASP.NET?Services (like web services) are Stateless.
This means if you make a second request to a server, it will not remember what your last request was.
ASP.NET adds the concept of State to web pagesThis allows you to have objects persist across
page requests
![Page 3: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/3.jpg)
Why Use State?Almost every page online uses state
It’s hard to find a meaningful static web pageState allows pages to dynamically respond to
different users and eventsExample Uses:
Enforcing page authenticationRemembering your shopping cartPersonalized search results
![Page 4: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/4.jpg)
State ObjectsSimply put: a collection of objects
Collection<string, object>Ex: Session[“UserId”] = 4;
Objects:SessionViewStateApplicationCacheCookies
![Page 5: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/5.jpg)
SessionLifetime:
From the first request til timeout/cleared sessionIt is possible for session to last longer than the
server host if stored using SQL Session StorageScope:
Only to the owner of the sessionPersists across pages. Inaccessible from other
sessionsUsage:
Accessing data shared across pages (ex. Login info)
![Page 6: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/6.jpg)
ViewStateLifetime:
The life of the pageRendered to the page
Scope: Just that request. Does not persist across pages or
across sessionsRebuilt for the following requests
Usage:Control selection data (form data, checkbox
selections, drop down list selections, etc.)
![Page 7: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/7.jpg)
ViewState<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTc0NTQxNTAwMWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgMFKWN0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkQ2hlY2tCb3hMaXN0MSQwBSljdGwwMCRDb250ZW50UGxhY2VIb2xkZXIxJENoZWNrQm94TGlzdDEkMQUpY3RsMDAkQ29udGVudFBsYWNlSG9sZGVyMSRDaGVja0JveExpc3QxJDFN/3diiSeYfuwsveCFZkB8GZhziyh9fxFB4N3DEHI9Ow==" />
![Page 8: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/8.jpg)
ApplicationLifetime:
The life of the application Persists until the service restarts
Scope:The entire applicationAll users in all sessions have access to this
objectUsage:
Application wide settingsConfiguration settings
![Page 9: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/9.jpg)
CacheLifetime:
Until the cached object expiresScope:
Application wideAll users in all sessions have access to this
objectUsage:
Stored commonly accessed data
![Page 10: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/10.jpg)
Cookies?
![Page 11: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/11.jpg)
CookiesLifetime:
Lifetime of the cookie Be kind to your users. Don’t forget to set an
expiration date on your cookiesScope:
The browserCan be accessed on any page in the cookie’s
domain (determined by browser security settings)Usage:
Quenching random hunger cravings
![Page 12: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/12.jpg)
Don’t do this:
![Page 13: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/13.jpg)
Strongly Typed StateRemember: a collection of objects
Collection<string, object>You can store any object in these collectionsWhat if you want to restrict the types objects
stored in the State?Enforce type in a typeless environment
Removes confusion about what’s stored in the object
![Page 14: Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,](https://reader035.fdocuments.net/reader035/viewer/2022070306/55179b6c5503460e6e8b5c18/html5/thumbnails/14.jpg)
Strongly Typed Statepublic int UserId{ get { if (!(Session["UserId"] is int)) Session["UserId"] = -1; return (int)Session["UserId"]; } set { Session["UserId"] = value; }}