MVC在session_end中获取会话[" x]值而没有this.Session和static? [英] MVC get session["x"] value in session_end without this.Session and static ?

查看:87
本文介绍了MVC在session_end中获取会话[" x]值而没有this.Session和static?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
我想知道如何在session_end(global.asax)中访问在控制器中分配的会话[xx]而不使用static或this.session并且特定实例(this.session)

Hi I 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 )

推荐答案

您无需使用任何这些关键字子句来访问会话变量的值。只需使用它,



You do not need to be using any of these clauses of keywords to access the values of session variables. Just use this,

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆