Aspnet5 - ServiceStack.Redis - 自定义会话提供程序
Aspnet5 - ServiceStack.Redis - custom session provider
在 .Net 的早期版本中,自定义会话状态提供程序在 web.config 中指定为
<system.web>
<sessionState mode="Custom" customProvider="ServiceStackRedisSessionStateProvider">
<providers>
<clear/>
<add name="RedisSessionStateProvider" type="clsServiceStackRedisSessionStateStoreProvider"/>
</providers>
</sessionState>
</system.web>
使用VS 2015,Aspnet5 RC1 - update1,在项目中添加session -> Startup.cs -> Configure方法使用以下代码
app.UseSession();
默认情况下,新的 AspNet5 Web 应用程序项目使用一些内置会话提供程序。
1.如何指定自定义会话状态提供者
2. 如何将 ServiceStack.Redis 添加为自定义会话状态提供程序
查看 Asp.Net 团队 https://github.com/aspnet/Session/tree/dev/samples/SessionSample
提供的样本
ServiceStack.Redis is not supported yet (current status - alpha2). I suggest you to take a look at Microsoft.Extensions.Caching.Redis 可能多一点 production-ready.
在您的 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();
在配置中
app.UseSession();
您还需要这些依赖项
"Microsoft.AspNet.Session": "1.0.0-rc1-final",
"Microsoft.Extensions.Caching.Redis": "1.0.0-rc1-final",
这只适用于完整的框架,不适用于 .net 核心
在 .Net 的早期版本中,自定义会话状态提供程序在 web.config 中指定为
<system.web>
<sessionState mode="Custom" customProvider="ServiceStackRedisSessionStateProvider">
<providers>
<clear/>
<add name="RedisSessionStateProvider" type="clsServiceStackRedisSessionStateStoreProvider"/>
</providers>
</sessionState>
</system.web>
使用VS 2015,Aspnet5 RC1 - update1,在项目中添加session -> Startup.cs -> Configure方法使用以下代码
app.UseSession();
默认情况下,新的 AspNet5 Web 应用程序项目使用一些内置会话提供程序。
1.如何指定自定义会话状态提供者
2. 如何将 ServiceStack.Redis 添加为自定义会话状态提供程序
查看 Asp.Net 团队 https://github.com/aspnet/Session/tree/dev/samples/SessionSample
提供的样本ServiceStack.Redis is not supported yet (current status - alpha2). I suggest you to take a look at Microsoft.Extensions.Caching.Redis 可能多一点 production-ready.
在您的 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();
在配置中
app.UseSession();
您还需要这些依赖项
"Microsoft.AspNet.Session": "1.0.0-rc1-final", "Microsoft.Extensions.Caching.Redis": "1.0.0-rc1-final",
这只适用于完整的框架,不适用于 .net 核心