无法获得Session工作ASP

时间:2015-10-15 23:46:24

标签: asp.net asp.net-mvc asp.net-core-mvc

将VS 2015与MVC 6的beta 7一起使用我遇到了将Session配置为在我的Web应用程序中使用的问题。

当我创建一个新的ASP.NET Web应用程序项目时,我选择了Web应用程序ASP.NET 5预览模板。

然后我通过添加以下行来编辑services.AddCaching();

services.AddSession();

然后我添加了以下行:

"Microsoft.AspNet.Session": "1.0.0-beta8"

此时编辑提示我添加对此依赖性的引用:

Error   CS7069  Reference to type 'IConfigurationProvider' claims it is defined in 'Microsoft.Framework.Configuration.Abstractions', but it could not be found  WebApplication1.DNX 4.5.1   c:\users\texasmike\documents\visual studio 2015\Projects\SessionTesting\src\WebApplication1\Startup.cs  29

Error   CS7069  Reference to type 'IConfigurationProvider' claims it is defined in 'Microsoft.Framework.Configuration.Abstractions', but it could not be found  WebApplication1.DNX Core 5.0    c:\users\texasmike\documents\visual studio 2015\Projects\SessionTesting\src\WebApplication1\Startup.cs  29

这样做后,我收到以下错误:

Startup.cs

我尝试过彻底的搜索但未找到任何答案。

以下是完整的using Microsoft.AspNet.Authentication.Facebook; using Microsoft.AspNet.Authentication.MicrosoftAccount; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.Data.Entity; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using WebApplication1.Models; using WebApplication1.Services; namespace WebApplication1 { public class Startup { public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { // Setup configuration sources. var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath) .AddJsonFile("config.json") .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true); if (env.IsDevelopment()) { // This reads the configuration keys from the secret store. // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709 builder.AddUserSecrets(); } builder.AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; set; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add Entity Framework services to the services container. services.AddEntityFramework() .AddSqlServer() .AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); // Add Identity services to the services container. services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); // Configure the options for the authentication middleware. // You can add options for Google, Twitter and other middleware as shown below. // For more information see http://go.microsoft.com/fwlink/?LinkID=532715 services.Configure<FacebookAuthenticationOptions>(options => { options.AppId = Configuration["Authentication:Facebook:AppId"]; options.AppSecret = Configuration["Authentication:Facebook:AppSecret"]; }); services.Configure<MicrosoftAccountAuthenticationOptions>(options => { options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"]; options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"]; }); // Add MVC services to the services container. services.AddMvc(); // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers. // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json. // services.AddWebApiConventions(); // Register application services. services.AddTransient<IEmailSender, AuthMessageSender>(); services.AddTransient<ISmsSender, AuthMessageSender>(); // Caching services.AddCaching(); // Session services.AddSession(); } // Configure is called after ConfigureServices is called. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.MinimumLevel = LogLevel.Information; loggerFactory.AddConsole(); loggerFactory.AddDebug(); // Configure the HTTP request pipeline. // Add the following to the request pipeline only in development environment. if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseErrorPage(); app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll); } else { // Add Error handling middleware which catches all application specific errors and // sends the request to the following path or controller action. app.UseErrorHandler("/Home/Error"); } // Add static files to the request pipeline. app.UseStaticFiles(); // Add cookie-based authentication to the request pipeline. app.UseIdentity(); // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method. // For more information see http://go.microsoft.com/fwlink/?LinkID=532715 // app.UseFacebookAuthentication(); // app.UseGoogleAuthentication(); // app.UseMicrosoftAccountAuthentication(); // app.UseTwitterAuthentication(); // Add MVC to the request pipeline. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); // Uncomment the following line to add a route for porting Web API 2 controllers. // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}"); }); } } }

project.json

以下是完整的{ "webroot": "wwwroot", "userSecretsId": "aspnet5-WebApplication1-36d27e1d-a781-4628-91dc-8a80cb46fd14", "version": "1.0.0-*", "dependencies": { "EntityFramework.Commands": "7.0.0-beta7", "EntityFramework.SqlServer": "7.0.0-beta7", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta7", "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta7", "Microsoft.AspNet.Authentication.Google": "1.0.0-beta7", "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta7", "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta7", "Microsoft.AspNet.Diagnostics": "1.0.0-beta7", "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7", "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta7", "Microsoft.AspNet.Mvc": "6.0.0-beta7", "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7", "Microsoft.AspNet.Server.IIS": "1.0.0-beta7", "Microsoft.AspNet.Server.WebListener": "1.0.0-beta7", "Microsoft.AspNet.Session": "1.0.0-beta8", "Microsoft.AspNet.StaticFiles": "1.0.0-beta7", "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7", "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7", "Microsoft.Framework.Configuration.Json": "1.0.0-beta7", "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7", "Microsoft.Framework.Logging": "1.0.0-beta7", "Microsoft.Framework.Logging.Console": "1.0.0-beta7", "Microsoft.Framework.Logging.Debug": "1.0.0-beta7", "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7" }, "commands": { "web": "Microsoft.AspNet.Hosting --config hosting.ini", "ef": "EntityFramework.Commands" }, "frameworks": { "dnx451": { }, "dnxcore50": { } }, "exclude": [ "wwwroot", "node_modules", "bower_components" ], "publishExclude": [ "node_modules", "bower_components", "**.xproj", "**.user", "**.vspscc" ], "scripts": { "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ] } }

{{1}}

0 个答案:

没有答案