ASP NET 5 WHAT HAPPENED TO SESSION AND

  • Slides: 7
Download presentation
ASP. NET 5 WHAT HAPPENED TO SESSION AND APPSETTINGS

ASP. NET 5 WHAT HAPPENED TO SESSION AND APPSETTINGS

Microsoft. Asp. Net. Session is Middleware forms a pipeline of components between Request and

Microsoft. Asp. Net. Session is Middleware forms a pipeline of components between Request and Response The Middleware pipeline is defined in the Configure method of Startup. cs The services need to be told to use Session in Configure. Services in Startup. cs Microsoft. Asp. NET is installed using a Nu. Get package It appears in the dependencies section on project. json

Session in ASP. NET 5 Session needs to be called in a controller through

Session in ASP. NET 5 Session needs to be called in a controller through Http. Context and has three pairs of methods: Set, Set. String, Set. Int 32, Get. String, Get. Int 32 Set can only accept a binary array as a parameter This is a bit of a problem Applications running on DNX (. NET Execution Environment) can target the. NET Framework or. NET Core. By default both are targeted. NET Core is a scaled down version of the. NET Framework designed to run on any platform However it does not contain System. Runtime. Serialization. Formatters. Binary

Using Set. String and Json for Session My solution was to create a generic

Using Set. String and Json for Session My solution was to create a generic class for Json Serialization using Newtonsoft. Json In my demo, I use Session to hold a generic list of shopping cart items Adding to Session becomes a matter of var json = Business. Logic. Serialization. Logic<List<Cart. Item. Model>>. Serialize(cart. Items); Http. Context. Session. Set. String("cart. Items", json); Retrieving from Session is var json = Http. Context. Session. Get. String("cart. Items"); return Business. Logic. Serialization. Logic<List<Cart. Item. Model>>. Deserialize(json);

App. Settings and Dependency Injection In ASP. NET 5, controllers allow dependency injection through

App. Settings and Dependency Injection In ASP. NET 5, controllers allow dependency injection through their constructors First we need to create a class, call it App. Settings to hold the settings A generic. NET class, IOptions<T> will be used to inject my settings into a Settings controller This is the sole purpose of IOptions<T> private IOptions<App. Settings> _app. Settings; public Settings. Controller(IOptions<App. Settings> app. Settings) { _app. Settings = app. Settings; }

Where do I specify the App. Settings? Your App. Settings need to be specified

Where do I specify the App. Settings? Your App. Settings need to be specified in appsettings. json "App. Settings": { "Message": "Hello KC. NET User Group" }, Configure. Services in Startup. cs needs to have the information to use this section: services. Configure<App. Settings>(Configuration. Get. Section("App. Settings"));

Resources Demo App on Git. Hub: https: //github. com/carolynlschroeder/Demo. App Power. Point presentation: http:

Resources Demo App on Git. Hub: https: //github. com/carolynlschroeder/Demo. App Power. Point presentation: http: //schroederconsulting. azurewebsites. net Blog: http: //carolynlschroederblog. com/category/home