AspNet 核心 rc2
包:Microsoft.AspNetCore.Session
HttpContext.Session.SetString(key,value) 错误。
我在 startUp.cs 中添加了代码。
public void ConfigureServices(IServiceCollection 服务) { // 添加框架服务 services.AddApplicationInsightsTelemetry(Configuration); services.AddAuthorization(); services.AddSession(选项=> { options.IdleTimeout = TimeSpan.FromDays(7); options.CookieName = ".FileSystem"; }); 服务.AddMvc(); }
公共无效配置(IApplicationBuilder 应用程序,IHostingEnvironment 环境,ILoggerFactory loggerFactory) { #地区 loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); 如果 (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } 别的 { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseMvc(路由=> { 路线.MapRoute( 名称:“默认”, 模板:“{controller=Home}/{action=Index}/{id?}”); }); #endregion app.UseSession(); } }
** 不工作。 HttpContext.session.setString()
我读过一些博客:asp.net core rc1。
博客显示我应该导入包:aspnet.session。
但是当我导入这个包时,这个包不支持 app.UseSession() 函数。
求助!如何在aspNet core RC2中使用session
中间件按照它们在代码中出现的顺序添加到管道中。 在这种情况下, UseSession
出现在UseMvc
; 因此它直到 Mvc 执行后才设置。 在您致电UseMvc
之前的某个时间添加它。 https://docs.asp.net/en/latest/fundamentals/middleware.html#creating -a-middleware-pipeline-with-iapplicationbuilder 有关于它是如何工作的非常有用的信息。
@pranavkm非常感谢。
无用
最有用的评论
中间件按照它们在代码中出现的顺序添加到管道中。 在这种情况下,
UseSession
出现在UseMvc
; 因此它直到 Mvc 执行后才设置。 在您致电UseMvc
之前的某个时间添加它。 https://docs.asp.net/en/latest/fundamentals/middleware.html#creating -a-middleware-pipeline-with-iapplicationbuilder 有关于它是如何工作的非常有用的信息。