Building Web Applications with Microsoft ASP

Slides:



Advertisements
Similar presentations
Overview  Introduction to ASP.NET caching  Output caching  Fragment caching  Data caching 1.
Advertisements

Building Scalable and Reliable Web Applications Vineet Gupta Technology Evangelist Microsoft Corporation
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Edwin Sarmiento Microsoft MVP – Windows Server System Senior Systems Engineer/Database Administrator Fujitsu Asia Pte Ltd
Microsoft ASP.NET: An Overview of Caching Holly Mazerolle Developer Support Engineer Microsoft Developer Support Microsoft Corporation.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
Software Architecture for ColdFusion Developers Unit 4: Application Events and Global Variables.
Advanced Web Forms with Databases Programming Right from the Start with Visual Basic.NET 1/e 13.
Microsoft ASP.NET: An Overview of Caching. 2 Overview  Introduction to ASP.NET caching  Output caching  Data caching  Difference between Data Caching.
Module 10: Monitoring ISA Server Overview Monitoring Overview Configuring Alerts Configuring Session Monitoring Configuring Logging Configuring.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
Caching Chapter 12. Caching For high-performance apps Caching: storing frequently-used items in memory –Accessed more quickly Cached Web Form bypasses:
Chapter 6 Server-side Programming: Java Servlets
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
ASP.NET State Management. Slide 2 Lecture Overview Client state management options Cookies Server state management options Application state Session state.
Session and Cookie Management in.Net Sandeep Kiran Shiva UIN:
ASP.NET Caching - Pradeepa Chandramohan. What is Caching? Storing data in memory for quick access. In Web Application environment, data that is cached.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Module 2: Overview of IIS 7.0 Application Server.
State Management. Agenda View state Application cache Session state ProfilesCookies.
Web Cache Consistency. “Requirements of performance, availability, and disconnected operation require us to relax the goal of semantic transparency.”
CP476 Internet Computing CGI1 Cookie –Cookie is a mechanism for a web server recall info of accessing of a client browser –A cookie is an object sent by.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
State Management. Agenda View state Application cache Session state ProfilesCookies.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
HTTP State Management Mechanisms with Multiple Addresses User Agents draft-vyncke-v6ops-happy-eyeballs- cookie-01 92nd IETF, Dallas, Mar 2015 V6OPS WG.
What’s new in ASP.NET 4.0 ?. Agenda Changes to Core Services  Extensible Output Caching  Shrinking Session State  Performance Monitoring  Permanently.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Active Server Pages Session - 3. Response Request ApplicationObjectContext Server Session Error ASP Objects.
Internationalization Andres Käver, IT Kolledž 2015.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
MVC5 Identity & Security Mait Poska & Andres Käver, IT Kolledž 2014.
Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Session, TempData, Cache Andres Käver, IT Kolledž
Raina NEC Application Object Describes the methods, properties, and collections of the object that stores information related to the entire Web.
Module 5: Managing Content. Overview Publishing Content Executing Reports Creating Cached Instances Creating Snapshots and Report History Creating Subscriptions.
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Building Web Applications with Microsoft ASP
Building Web Applications with Microsoft ASP
Managing State Chapter 13.
Building Web Applications with Microsoft ASP
Building production ready APIs with ASP.NET Core 2.0
Building Web Applications with Microsoft ASP
Building Web Applications with Microsoft ASP
Caching Data in ASP.NET MVC
Session Variables and Post Back
State Management.
Sessions Many interactive Web sites spread user data entry out over several pages: Ex: add items to cart, enter shipping information, enter billing information.
Building Web Applications with Microsoft ASP
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
Building Web Applications with Microsoft ASP
CloudFront: Living on the Edge
ASP.NET Caching.
Web Caching? Web Caching:.
Building Web Applications with Microsoft ASP
The Request & Response object
Web Systems Development (CSC-215)
CS320 Web and Internet Programming Cookies and Session Tracking
Sessions Many interactive Web sites spread user data entry out over several pages: Ex: add items to cart, enter shipping information, enter billing information.
ASP.NET 4.0 State Management Improvements – Deep Dive
Building ASP.NET Applications
RESTful Web Services.
Building Web Applications with Microsoft ASP
Building Web Applications with Microsoft ASP
C# - Razor Pages Db/Scaffolding/Async
Caching.
Presentation transcript:

Building Web Applications with Microsoft ASP Building Web Applications with Microsoft ASP.NET - I376 Web Application Programming II – I713 IT College, Andres Käver, 2016-2017, Spring semester Web: http://enos.Itcollege.ee/~akaver/ASP.NETCore Skype: akaver Email: akaver@itcollege.ee

State HTTP is a stateless protocol. A web server treats each HTTP request as an independent request and does not retain user values from previous requests.

Cache Do you always need live data? Or maybe few tens of seconds old data is still ok? Maybe few minutes old data is ok? ASP.NET Core supports several cache mechanisms In memory caching Local – cache is stored in the same web server All sessions should return to same server (azure supports this) Distributed Separate server for caching, all web servers share it. Web restarts, deploys, different web servers servicing requests – cache continues to work

Cache IMemoryCache Entries are removed when server is under memory pressure Set CacheItemPriority to regulate this (CacheItemPriority.NeverRemove) IMemoryCache stores any object (distributed cache stores only byte[])

Cache - IMemoryCache Used with typical dependency injection pattern Microsoft.Extensions.Caching.Memory public void ConfigureServices(IServiceCollection services) { services.AddMemoryCache(); services.AddMvc(); } public class HomeController : Controller { private IMemoryCache _cache; public HomeController(IMemoryCache memoryCache) _cache = memoryCache; }

Cache public IActionResult CacheTryGetValueSet() { DateTime cacheEntry; // Look for cache key. if (!_cache.TryGetValue(CacheKeys.Entry, out cacheEntry)) { // Key not in cache, so get data. cacheEntry = DateTime.Now; // Set cache options. var cacheEntryOptions = new MemoryCacheEntryOptions() // Keep in cache for this time, reset time if accessed. .SetSlidingExpiration(TimeSpan.FromSeconds(15)); // Save data in cache. _cache.Set(CacheKeys.Entry, cacheEntry, cacheEntryOptions); } return View("Cache", cacheEntry);

Cache - IMemoryCache IMemoryCache CreateEntry(Object) - Create or overwrite an entry in the cache Remove(Object) - Removes the object associated with the given key TryGetValue(Object, out Object) - Gets the item associated with this key if present.

Cache - CacheExtensions Get(IMemoryCache, Object) Get<TItem>(IMemoryCache, Object) GetOrCreate<TItem>(IMemoryCache, Object, Func<ICacheEntry, TItem>) GetOrCreateAsync<TItem>(IMemoryCache, Object, Func<ICacheEntry, Task<TItem>>) Set<TItem>(IMemoryCache, Object, TItem) Set<TItem>(IMemoryCache, Object, TItem, MemoryCacheEntryOptions) Set<TItem>(IMemoryCache, Object, TItem, IChangeToken) Set<TItem>(IMemoryCache, Object, TItem, DateTimeOffset) Set<TItem>(IMemoryCache, Object, TItem, TimeSpan) TryGetValue<TItem>(IMemoryCache, Object, out TItem)

Cache - MemoryCacheEntryOptions AbsoluteExpiration Gets or sets an absolute expiration date for the cache entry. AbsoluteExpirationRelativeToNow Gets or sets an absolute expiration time, relative to now. ExpirationTokens Gets the IChangeToken instances which cause the cache entry to expire. PostEvictionCallbacks Gets or sets the callbacks will be fired after the cache entry is evicted from the cache. Priority Gets or sets the priority for keeping the cache entry in the cache during a memory pressure triggered cleanup. The default is Normal (High, Low, Normal, NeverRemove). SlidingExpiration Gets or sets how long a cache entry can be inactive (e.g. not accessed) before it will be removed. This will not extend the entry lifetime beyond the absolute expiration (if set).

Response caching Response caching adds cache-related headers to responses. How do you want client, proxy and middleware to cache responses HTTP header used for caching is Cache-Control Public, private, no-cache, Pragma, Vary Disable caching for content that contains information for authenticated clients. Caching should only be enabled for content that does not change based on a user's identity, or whether a user is logged in.

Response caching ResponseCache Attribute VaryByQueryKeys string[] Response is cached by middleware, based on query keys [ResponseCache(VaryByQueryKeys = new []{"foo","bar"}, Duration = 30)] public IActionResult Index(string foo, string bar) {

Response caching VaryByHeader [ResponseCache(VaryByHeader = "User-Agent", Duration = 30)] public IActionResult About2() {

Response caching NoStore and Location.None NoStore overrides most of the other properties. When this property is set to true, the Cache-Control header will be set to "no-store". If Location is set to None: Cache-Control is set to "no-store, no-cache". Pragma is set to no-cache. If NoStore is false and Location is None, Cache-Control and Pragma will be set to no-cache. You typically set NoStore to true on error pages

Response caching Location and Duration To enable caching, Duration must be set to a positive value and Location must be either Any (the default) or Client.

Response caching Cache Profiles public void ConfigureServices(IServiceCollection services) { services.AddMvc(options => options.CacheProfiles.Add("Default", new CacheProfile() Duration = 60 }); options.CacheProfiles.Add("Never", Location = ResponseCacheLocation.None, NoStore = true } Cache Profiles

Response caching Cache profiles [ResponseCache(Duration = 30)] public class HomeController : Controller { [ResponseCache(CacheProfileName = "Default")] public IActionResult Index() return View(); } Cache profiles

Response caching RFC 7234 - https://tools.ietf.org/html/rfc7234#section-3 RFC2616 - https://www.w3.org/Protocols/rfc2616/rfc2616- sec14.html#sec14.9

Caching middleware Microsoft.AspNetCore.ResponseCaching public void ConfigureServices(IServiceCollection services) { services.AddResponseCaching(); } services.AddResponseCaching(options => { options.UseCaseSensitivePaths = true; options.MaximumBodySize = 1024; });

Session User specific dictionary on webserver Backed by cache public class Startup { public void ConfigureServices(IServiceCollection services){ ... // Default in-memory implementation of IDistributedCache. services.AddDistributedMemoryCache(); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromSeconds(10); options.CookieHttpOnly = true; }); } public void Configure(IApplicationBuilder app) { app.UseSession(); ...

Session Getting and setting public class HomeController : Controller { const string SessionKeyName = "_Name"; public IActionResult Index() HttpContext.Session.SetString(SessionKeyName, "Rick"); return RedirectToAction("SessionName"); } public IActionResult SessionName() var name = HttpContext.Session.GetString(SessionKeyName); return Content($"Name: \"{name}\"");

Session - extension using Microsoft.AspNetCore.Http; using Newtonsoft.Json; public static class SessionExtensions { public static void Set<T>(this ISession session, string key, T value) session.SetString(key, JsonConvert.SerializeObject(value)); } public static T Get<T>(this ISession session,string key) var value = session.GetString(key); return value == null ? default(T) : JsonConvert.DeserializeObject<T>(value);

Session vs cache Cache – shared among all users Session – private to every user

THE END