问题描述
Hi
我想知道如何在session_end(global.asax)中访问在控制器中分配的会话[xx]而不使用static或this.session并且特定实例(this.session)
HiI would like to know how to access a session["xx"] assigned in a controller, in session_end(global.asax) without using "static" or "this.session" and which takes its specific instance (this.session )
推荐答案
var val = Session["x"];
但由于变量可能不存在,而不是上面的代码,使用以下内容忽略任何运行时错误,
But since the variable might not exist, instead of above code, use the following to ignore any runtime errors,
if(Session["x"] != null) {
// variable exists
var val = Session["x"];
}
现在val将在x的Session变量中设置值。您可以在应用程序的任何页面中使用这些变量,它们在整个会话中都存在。
Now val would have the value set in the Session variable for x. You can use these variable in any page on the application, they exist throughout the session.
这篇关于MVC在session_end中获取会话[" x]值而没有this.Session和static?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!