【问题标题】:Session not works in C#会话在 C# 中不起作用
【发布时间】:2014-04-12 07:22:33
【问题描述】:

我尝试在 C# 中进行会话。我刚开始学习一段时间,我被困在这里。我试过的代码:

第一:

Session["Status"] = "hehehe";

结果:

The name 'Session' does not exist in the current context    

第二次测试:

HttpContext.Current.Session["Status"] = "hehehe";

结果:

The name 'HttpContext' does not exist in the current context

所以我目前被困在这里,在顶部我正在使用:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

【问题讨论】:

  • 您需要添加using System.Web;
  • -1 表示缺乏努力
  • Windows 窗体应用程序中Session 的意义是什么(假设在使用System.Windows.Forms 之后)?
  • 非常感谢@Caleb,这是对的。当它在 cmets tho 中时,我无法接受你的答案:/

标签: c# session


【解决方案1】:

您似乎正试图在 Windows 窗体中使用它(正如using System.Windows.Forms; 所说)。 Windows 应用程序没有会话的概念,因为会话旨在用于在服务器上管理连接到服务器的客户端。如果您正在开发连接到服务器的应用程序(例如通过 API),您可能需要管理从服务器发送到您的应用程序的会话 cookie。

【讨论】:

    猜你喜欢
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 2018-10-30
    相关资源
    最近更新 更多