01.Download last redis from download , install and start the service from services.msc redis
02. Add two libraries to project.json
"Microsoft.Extensions.Caching.Redis.Core": "1.0.3", "Microsoft.AspNetCore.Session": "1.1.0",
03.Add dependency injection to
public void ConfigureServices(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); services.AddMvc();
and in the Configure
method add top app.UseMvc line
app.UseSession ();
use redis in the session store in the asp.net core. Now you can use this as HomeController.cs
public class HomeController : Controller { private readonly IDistributedCache _distributedCache; public HomeController(IDistributedCache distributedCache) { _distributedCache = distributedCache; } //Use version Redis 3.22 //http://stackoverflow.com/questions/35614066/redissessionstateprovider-err-unknown-command-eval public IActionResult Index() { _distributedCache.SetString("helloFromRedis", "world"); var valueFromRedis = _distributedCache.GetString("helloFromRedis"); return View(); } }
source share