好吧,最近我在为 ASP.NET vNext (MVC 6) 使用新的 Microsoft.AspNet.Session 中间件时遇到了很多麻烦。我得到的错误,
Unable to resolve service for type 'Microsoft.Framework.OptionsModel.ConfigureOptions[Microsoft.AspNet.Session.SessionOptions] while attempting to activate 'Microsoft.AspNet.Session.SessionMiddleware'
发生在所有页面上,与 session 使用无关。我使用的 DNVM 版本是 Beta5 x86,项目中的所有包也是 Beta5。该项目本身是尝试将 ASP.NET MVC 5 项目移植到 MVC 6,但运气不佳。以下是可能重要的资源链接:
- Project.json:http://tinyurl.com/project-json
- Startup.cs:http://tinyurl.com/startup-cs
这似乎是我的配置有问题,但我不确定该怎么办...请发送帮助 Dx
最佳答案
Unable to resolve service for type 'Microsoft.AspNetCore.Session.ISessionStore' while attempting to activate 'Microsoft.AspNetCore.Session.SessionMiddleware'
如果您在 ASP.NET Core 中收到此错误消息,则需要在 Startup.cs 中配置 session 服务:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddSessionStateTempDataProvider();
services.AddSession();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseSession();
app.UseMvcWithDefaultRoute();
}
关于c# - ASP.NET MVC 6 AspNet.Session 错误 - 无法解析类型服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31886779/