Cookie-based TempData provider for ASP.NET Core MVC
C# PowerShell Shell
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
tools
.gitignore
.travis.yml
AspNetCore.Mvc.CookieTempData.sln
README.md
appveyor.yml
build.cake
build.ps1
build.sh
global.json

README.md

AspNetCore.Mvc.CookieTempData

AppVeyor build status Travis CI build status NuGet

Cookie-based TempData provider for ASP.NET Core MVC applications. TempData values are serialized in BSON and protected via the data protection API.

NOTE: ASP.NET Core 1.1.0 will include a built-in cookie-based TempData provider.

Usage

Installation

This project is available as a NuGet package at https://www.nuget.org/packages/AspNetCore.Mvc.CookieTempData/.

Configuration

On the ConfigureServices method of your Startup class just add a call to AddCookieTempData. This will replace MVC's default TempData provider - which uses session storage - with the cookie-based provider.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddCookieTempData();
}

Important note: you should configure data protection to fit your deployment scenarios. The library uses purpose strings appropriately but no configuration is done on the data protection system.

Additional configurations can be done using the options pattern:

services.AddCookieTempData(o => 
{
    o.CookieName = "t";
});

Limitations

By default, MVC saves TempData at a stage where it may be too late to access response cookies. To be able to safely use response cookies, the library saves TempData a bit earlier. As a side effect, the latest stage of the filter chain on which you can modify TempData is IResultFilter.OnResultExecuting. Changes made after this point are not persisted. This shouldn't be a problem for most application, as TempData is usually used within action methods.

Acknowledgements

This project is heavily inspired on Brock Allen's CookieTempData, which targets previous versions of ASP.NET MVC.