微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决“ 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 举报,一经查实,本站将立刻删除。