C# HttpContext.Session是在哪个模块中定义的
我在MVC核心应用程序。我将System.Web添加到using子句中,但仍然无法访问httpcontext.Session。intellisense没有为httpcontext提供任何选项。谢谢你的回答 编辑: 我找到了这个答案: 但是,当我将nuget包:Microsoft.AspNetCore.Session添加到我的项目中时,解决方案甚至不再加载。所以我不得不把它移走 编辑:现在我已经从nuget控制台添加了最新版本的包。但我仍然没有intellisense中的HttpContext选项,因此无法访问会话。请帮忙 在System.Web中,我只有以下对象:HttpUtility,仅此而已, 有人能帮忙吗?没有会话,我无法编写任何应用程序。我应该重新安装Visual Studio吗 注意**:在我的webforms应用程序中,对象会话位于system.web中 根据需要,我发布Startup.cs和试图调用对象会话的文件:C# HttpContext.Session是在哪个模块中定义的,c#,asp.net-mvc,session,C#,Asp.net Mvc,Session,我在MVC核心应用程序。我将System.Web添加到using子句中,但仍然无法访问httpcontext.Session。intellisense没有为httpcontext提供任何选项。谢谢你的回答 编辑: 我找到了这个答案: 但是,当我将nuget包:Microsoft.AspNetCore.Session添加到我的项目中时,解决方案甚至不再加载。所以我不得不把它移走 编辑:现在我已经从nuget控制台添加了最新版本的包。但我仍然没有intellisense中的HttpContext选项
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?}");
});
}
}
}
你能用你到目前为止尝试过的更多信息来更新你的问题吗?在过去,当我的项目无法加载引用时,我一直在尝试引用目标框架的版本和程序集或其他依赖项的框架版本。我建议你检查/确认他们都在sync@JayV我该如何检查版本是否同步?能否将startup.cs和controller发布到访问会话代码的位置。因此,我们将获得更好的清晰度。@user1238784对于您自己的项目,请参见其项目属性。对于其他组件,请参阅此问题:
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
}
}
}