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
}
}
}