Asp.NET C#从类到处理程序的会话变量
为了避免使用querystring,我正在尝试使用会话变量来传递所需的值。 我是从一个类到一个处理程序 在我使用的课堂中:Asp.NET C#从类到处理程序的会话变量,c#,asp.net,class,session,handler,C#,Asp.net,Class,Session,Handler,为了避免使用querystring,我正在尝试使用会话变量来传递所需的值。 我是从一个类到一个处理程序 在我使用的课堂中: HttpContext.Session["name"] = "Value"; 在我使用的处理程序中: var name = context.Session["name"]; 我已经添加了IReadOnlySessionState或irerequiresessionstate,但会话变量仍然为空 有什么帮助吗?我想你又在创造新的环境了。您应该使用HttpContext.C
HttpContext.Session["name"] = "Value";
在我使用的处理程序中:
var name = context.Session["name"];
我已经添加了IReadOnlySessionState
或irerequiresessionstate
,但会话变量仍然为空
有什么帮助吗?我想你又在创造新的环境了。您应该使用
HttpContext.Current
使用相同的会话。
尝试下面的代码,并参考我在下面添加的注释
string firstName = "Jeff";
string lastName = "Smith";
string city = "Seattle";
// Save to session state in a Web Forms page class.
Session["FirstName"] = firstName;
Session["LastName"] = lastName;
Session["City"] = city;
// Read from session state in a Web Forms page class.
firstName = (string)(Session["FirstName"]);
lastName = (string)(Session["LastName"]);
city = (string)(Session["City"]);
// Outside of Web Forms page class, use HttpContext.Current.
HttpContext context = HttpContext.Current;
context.Session["FirstName"] = firstName;
firstName = (string)(context.Session["FirstName"]);
你好谢谢你的回答。。。但它不起作用。。。我正在设置类中的值,但在处理程序上,它仍然为null。