【问题标题】:Getting error while assign a value to session为会话赋值时出错
【发布时间】:2014-09-06 06:36:51
【问题描述】:

我正在使用 c# 在 asp.net 中开发一个应用程序。在我的代码段中,我必须为会话变量设置一个值。当我试图为会话分配一个值时,它给了我一个名为“对象引用未设置为对象的实例”的错误。我不知道它为什么会来。代码如下

Session["User_ID"]="shubhadeepchat@gmail.com";

请帮帮我。

【问题讨论】:

  • 是你得到错误的那一行吗?还是其他线路?
  • @Arbaaz 在这一行我遇到了错误。
  • @Arbaaz 问题已解决

标签: c# asp.net session


【解决方案1】:
public class Set
{
     public string setSession()
    {
        HttpContext.Current.Session["User_ID"] = "shubhadeepchat@gmail.com";
        return HttpContext.Current.Session["User_ID"].ToString();
    }
}

现在在后面的代码中创建一个 setSession 的实例。调用方法 setSession 并查看输出为 shubhadeepchat@gmail.com。

在 page_load 事件中尝试此代码

Set objset = new Set();
Response.Write(objset .setSession());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-22
    • 2015-05-08
    • 1970-01-01
    • 2012-07-12
    相关资源
    最近更新 更多