Skip to content

Instantly share code, notes, and snippets.

@tanaka-takayoshi
Last active December 16, 2016 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanaka-takayoshi/5fd824d0293acfb47a8f527262a06fae to your computer and use it in GitHub Desktop.
Save tanaka-takayoshi/5fd824d0293acfb47a8f527262a06fae to your computer and use it in GitHub Desktop.
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";
});
services.AddSession();
}
// 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)
{
app.UseSession();
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//please add code to confirm session is wokring.
//you can find full code https://github.com/tanaka-takayoshi/aspnetcore-redis-session-example
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment