Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 6 AspNet.Session Errors - Unable to resolve service for type?

Alright, so recently I've been having a lot of trouble using the new Microsoft.AspNet.Session middleware for ASP.NET vNext (MVC 6). The error I'm getting,

Unable to resolve service for type 'Microsoft.Framework.OptionsModel.ConfigureOptions[Microsoft.AspNet.Session.SessionOptions] while attempting to activate 'Microsoft.AspNet.Session.SessionMiddleware'

occurs on all pages regardless of session use. The DNVM version I'm using is Beta5 x86 and all the packages in the project are Beta5 as well. The project itself is an attempt at porting an ASP.NET MVC 5 project to MVC 6 without much luck. Below are links to resources that may be important:

  • Project.json: http://tinyurl.com/project-json
  • Startup.cs: http://tinyurl.com/startup-cs

It seems to be a problem with my configuration but I'm not sure what to do about it... Pls send help Dx

like image 942
PlsBroSendHelp Avatar asked Aug 07 '15 21:08

PlsBroSendHelp


2 Answers

Unable to resolve service for type 'Microsoft.AspNetCore.Session.ISessionStore' while attempting to activate 'Microsoft.AspNetCore.Session.SessionMiddleware'

If you get this error message in ASP.NET Core, you need to configure the session services in Startup.cs:

public void ConfigureServices(IServiceCollection services) {     services.AddMvc()         .AddSessionStateTempDataProvider();     services.AddSession(); }  public void Configure(IApplicationBuilder app, IHostingEnvironment env) {     app.UseSession();     app.UseMvcWithDefaultRoute(); } 
like image 82
Run CMD Avatar answered Sep 21 '22 21:09

Run CMD


This code helps you...

In Startup.cs file

public void ConfigureServices(IServiceCollection services)     {         ....         services.AddSession(options =>         {             options.IdleTimeout = TimeSpan.FromMinutes(30);//We set Time here              options.Cookie.HttpOnly = true;             options.Cookie.IsEssential = true;         });         ...     }    public void Configure(IApplicationBuilder app, IHostingEnvironment env)     {         app.UseSession();         app.UseMvc();     } 

Thanks!!!

like image 41
Nitika Chopra Avatar answered Sep 20 '22 21:09

Nitika Chopra