在哪个模块中定义了HttpContext.Session

时间:2018-05-26 07:40:39

标签: c# asp.net-mvc session

我在MVC Core应用程序中。我将System.Web添加到了我的using子句中,但仍然无法访问httpcontext.Session。 intellisense没有给我任何httpcontext选项。谢谢你的回答。

编辑: 我找到了这个答案:https://benjii.me/2016/07/using-sessions-and-httpcontext-in-aspnetcore-and-mvc-core/ 但是当我将nuget包:Microsoft.AspNetCore.Session添加到我的项目中时,解决方案甚至不再加载。所以我不得不删除它 编辑:现在我已经从nuget控制台添加了最新版本的软件包。但我仍然没有智能感知中的HttpContext选项,所以我无法访问会话。请帮忙..

在System.Web中,我只有以下对象:HttpUtility,仅此而已, 有人可以帮忙吗?没有会话我不能写任何应用程序。我应该重新安装Visual Studio吗?

注意**:在我的webforms应用程序中,我在system.web中有对象Session

根据需要,我发布了我的Startup.cs和我试图调用对象Session的文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Localization;
using WebCoreFly.Models;

namespace WebCoreFly
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddDbContext<FlyDBContext>(options =>
                    options.UseSqlServer(Configuration["Data:WebCoreFly:ConnectionString"]));
            services.AddSingleton<FlyRepository>();

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

我试图呼叫会话的班级:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;



 namespace WebCoreFly.Models.ViewModels
{
        public class UserRepository1 
        {
            public UserRepository1()  
            {
               System.Web.HttpContext  //does not recognize it        

            }

        }

    }

0 个答案:

没有答案