Last active
December 16, 2016 14:34
-
-
Save tanaka-takayoshi/5fd824d0293acfb47a8f527262a06fae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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