“ HttpSessionStateBase”不包含“ SetString”的定义,也没有可访问的扩展方法

问题描述

我尝试将数据从一个视图传递到ASP.NET MVC中的另一个视图。 因此,我尝试使用HttpContext.Session.SetString("Username",model.UserName.ToString());

我收到了这些错误消息

'HttpSessionStateBase'不包含'SetString'的定义 并且没有可访问的扩展方法'SetString'接受第一个 可以找到类型为'HttpSessionStateBase'的参数”。

我的代码在下面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DemoEmployee.Models;
using System.Web.Security;
using System.Web.UI.WebControls;
using Microsoft.AspNetCore.Http;

[HttpPost]
public ActionResult Login(Models.Member model)
{ 
    var userr = db.User
        .Where(x => x.UserName == model.UserName && 
            x.Password == model.Password)
        .FirstOrDefault();
            
    name = model.UserName;
   
    if (userr == null)
    {
        ModelState.AddModelError("","Invalid username and password");
        FormsAuthentication.SetAuthCookie(model.UserName,false);
    }
    else
    {           
        // Try to make sesstion to another page
        HttpContext.Session.SetString("Username",model.UserName.ToString()); 

        return RedirectToAction("Empinput","Empinput");
    }

    return View();
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)