Navaneeth
Navaneeth

Reputation: 447

Aspnet5 - ServiceStack.Redis - custom session provider

In earlier versions of .Net, custom session state provider was specified in web.config as

<system.web>
    <sessionState mode="Custom" customProvider="ServiceStackRedisSessionStateProvider">
      <providers>
        <clear/>
        <add name="RedisSessionStateProvider" type="clsServiceStackRedisSessionStateStoreProvider"/>
      </providers>
    </sessionState>
</system.web>

Using VS 2015, Aspnet5 RC1 - update1, to add session in the project -> Startup.cs -> Configure method the following code is used

 app.UseSession();

By default, a new AspNet5, web application project uses some in built session provider.
1. How to specify custom session state provider
2. How to add ServiceStack.Redis as custom session state provider

Upvotes: 1

Views: 568

Answers (3)

Tom
Tom

Reputation: 836

in your ConfigureServices

services.AddSingleton<IDistributedCache, RedisCache>(); //this replaces the default in memory cache with Rdis
services.Configure<RedisCacheOptions>(redisOptions =>
            {
                redisOptions.Configuration = Configuration["Redis:Configuration"]; //ie - localhost
                redisOptions.InstanceName = Configuration["Redis:InstanceName"];
            });
services.AddCaching();

in Configure

app.UseSession();

also you will need these dependencies

"Microsoft.AspNet.Session": "1.0.0-rc1-final", "Microsoft.Extensions.Caching.Redis": "1.0.0-rc1-final",

and this only works with the full framework, not .net core

Upvotes: 1

vzayko
vzayko

Reputation: 335

ServiceStack.Redis is not supported yet (current status - alpha2). I suggest you to take a look at Microsoft.Extensions.Caching.Redis which is probably bit more production-ready.

Upvotes: 0

Ankit Sinha
Ankit Sinha

Reputation: 421

Have a look at samples provided by Asp.Net Team https://github.com/aspnet/Session/tree/dev/samples/SessionSample

Upvotes: 0

Related Questions