我正在使用c#在asp.net中开发应用程序。在我的代码段中,我必须为会话变量设置一个值。当我尝试为会话分配值时,它给我一个错误,叫做“对象引用未设置为对象的实例”。我不知道为什么会这样。代码如下
Session["User_ID"]="[email protected]";
请帮我。
public class Set
{
public string setSession()
{
HttpContext.Current.Session["User_ID"] = "[email protected]";
return HttpContext.Current.Session["User_ID"].ToString();
}
}
现在,在后面的代码中创建setSession的实例。调用方法setSession并将输出显示为[email protected]。
在page_load事件上尝试此代码
Set objset = new Set();
Response.Write(objset .setSession());
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句