0

I am in MVC Core application. I added System.Web to my using clause but still I cannot access httpcontext.Session. The intellisense does not give me any option for httpcontext. Thanks for your answer.

Edit: I have found this answer: https://benjii.me/2016/07/using-sessions-and-httpcontext-in-aspnetcore-and-mvc-core/ But when I add the nuget package: Microsoft.AspNetCore.Session into my project the solution won't even load anymore. So I had to remove it Edit: Now I have added the most recent version of the package from nuget console. But I still do not have HttpContext option in the intellisense so I cannot access the session. Please help..

In System.Web I have only the following object: HttpUtility and nothing more, is there anyone that can help? Without Sessions I cannot write any applications. Should I reinstall Visual Studio?

Notice**: In my webforms application I have the object Session in system.web

As required I post my Startup.cs and the file in which I am trying to call the object 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?}");
            });
        }
    }
}

the class in whic I am trying to call session:

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        

            }

        }

    }
user1238784
  • 2,250
  • 3
  • 22
  • 41
  • can you update your question with some more information what you have tried so far? – ArunPratap May 26 '18 at 07:44
  • In the past when my projects can't load references it has been down to the version of the target framework and the framework version of the assembly or other dependents that I am trying to reference. I would suggest that you check/confirm they are all in sync – JayV May 26 '18 at 08:21
  • @JayV ho do I check the versions are in sync? – user1238784 May 26 '18 at 08:22
  • can you post your startup.cs and controller where you are accessing the session code here. So we will get a better clarity. – Trilok Kumar May 26 '18 at 09:06
  • @user1238784 For your own project, see its Project Properties. For other assemblies, refer to this question: https://stackoverflow.com/questions/2310701/determine-framework-clr-version-of-assembly – JayV May 26 '18 at 11:47

0 Answers0