Net Core MVC:当前上下文中不存在名称会话 [英] Net Core MVC: Name Session does not exist in Current Context
本文介绍了Net Core MVC:当前上下文中不存在名称会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在最后一行收到一个错误。我该如何解决?尝试将Net 4.6.2项目转换为MVC Net Core。
I am receiving an error in the last line. How would I resolve this? Trying to convert Net 4.6.2 Project to MVC Net Core.
Last Line Error: Name Session does not exist in Current Context.
public class TransferPropertyOwnershipController : Controller
{
public ActionResult GetNewOwnerRecord(int ownerID, int propertyID)
{
OwnerManager ownerManager = new OwnerManager();
var newOwner = ownerManager.Get(ownerID, true);
PropertyOwnerRoleViewModel newPropertyOwnerRoleViewModel = new PropertyOwnerRoleViewModel();
newPropertyOwnerRoleViewModel.OwnerID = newOwner.OwnerID;
newOwner.Address = new Model.Address();
newPropertyOwnerRoleViewModel.Owner = newOwner;
newPropertyOwnerRoleViewModel.IsPrimaryOwner = false;
newPropertyOwnerRoleViewModel.OwnershipPercentage = 0;
newPropertyOwnerRoleViewModel.PropertyID = propertyID;
IQueryable<PropertyOwnerRoleViewModel> currentOwnersResult = Session[_currentOwnersResult] as IQueryable<PropertyOwnerRoleViewModel>;
建议的解决方案:
数字1
HttpContext.Session.GetString(_currentOwnersResult])
Error Text: 'ISession' does not contain a definition for 'GetString' and no accessible extension method 'GetString' accepting a first argument of type 'ISession' could be found (are you missing a using directive or an assembly reference?)
数字2
IQueryable<PropertyOwnerRoleViewModel> currentOwnersResult = HttpContext.Current.Session(_currentOwnersResult]) as IQueryable<PropertyOwnerRoleViewModel>;
Error Text: 'HttpContext' does not contain a definition for 'Current' and no accessible extension method 'Current' accepting a first argument of type 'HttpContext' could be found (are you missing a using directive or an assembly reference?)
资源:
尝试使用此解决方案,但遇到问题。
会话在当前上下文中不存在
Trying to utilize this solution, but having issues. 'Session' does not exist in the current context
推荐答案
您需要在启动中添加服务。cs
public void ConfigureServices(IServiceCollection services)
{
....
services.AddSession(options =>
{
});
....
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
.....
app.UseSession();
....
}
这篇关于Net Core MVC:当前上下文中不存在名称会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文