在早期版本的.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,在项目中添加会话 - &gt; Startup.cs - &gt;配置方法使用以下代码
app.UseSession();
默认情况下,新的AspNet5 Web应用程序项目会在构建的会话提供程序中使用一些
1.如何指定自定义会话状态提供者
2.如何将ServiceStack.Redis添加为自定义会话状态提供程序
答案 0 :(得分:0)
查看Asp.Net团队提供的示例https://github.com/aspnet/Session/tree/dev/samples/SessionSample
答案 1 :(得分:0)
ServiceStack.Redis is not supported yet(当前状态 - alpha2)。我建议你看看Microsoft.Extensions.Caching.Redis,它可能更适合生产。
答案 2 :(得分:0)
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核心