Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace SessionExample
public class Startup
public void ConfigureServices(IServiceCollection services)
//retrieve connectoin info from environment variables in this sample
var host = Environment.GetEnvironmentVariable("REDIS_SESSION_SERVICE_HOST");
var port = Environment.GetEnvironmentVariable("REDIS_SESSION_SERVICE_PORT");
var conn = $"{host}:{port}";
services.AddDistributedRedisCache(option =>
option.Configuration = conn;
option.InstanceName = "master";
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
if (env.IsDevelopment())
//please add code to confirm session is wokring.
//you can find full code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment