AngryHacker
AngryHacker

Reputation: 61636

How can I make a custom session provider work with ASP.NET 5? Specically use Redis for sessions

In ASP.NET MVC 4, to switch out the default session provider for a custom one, you had to let the app know via web.config, which now is gone in ASP.NET 5.

I've tried to use Microsoft.Web.RedisSessionStateProvider (which is based on StackExchange.Redis), but not sure how to proceed beyond getting it via NuGet. It simply doesn't work.

What am I missing?

Upvotes: 4

Views: 1171

Answers (2)

opiethehokie
opiethehokie

Reputation: 1912

At one point a couple months ago I had an app (similar to https://github.com/aspnet/Session/blob/dev/samples/SessionSample/Startup.cs) connecting to a remote Redis server like this:

app.UseDistributedSession(new RedisCache(new RedisCacheOptions() 
{ 
     Configuration = "ip:port,password=xxx"
}));

It's probably different now in beta7, but hopefully that helps.

Upvotes: 3

Kiran
Kiran

Reputation: 57979

Following is a Session sample where you can use Redis cache as a store for it:

https://github.com/aspnet/Session/blob/dev/samples/SessionSample/Startup.cs#L32-L39

You can configure Redis cache options like below:

services.Configure<RedisCacheOptions>(redisOptions =>
{
    redisOptions.Configuration = "localhost";
    redisOptions.InstanceName = "SampleInstance";
}

Upvotes: 3

Related Questions