问题描述
大家好,
这里我在正常页面中使用会话值。现在我想传入app_Code文件页面(逻辑页面我需要会话值)。下面的代码用于我的申请,但我出现空值。
正常页码:(。CS)
hi to all,
Here i using session value in normal page.now i want to pass in app_Code file page (logic page i need the session value).following below code is used in my application but i occur null values.
Normal page code: (.CS)
string mac1 = string.Empty;
string mac1 = string.Empty;
string mac = string.Empty;
// GetMACAddress();
mac = macAddress.Value;
//
Session["macAddress"] = mac;
mac1 = Session["macAddress"].ToString();
APP_CODE
logic.cs: -
string mac2 = System.Web.HttpContext.Current.Session [macAddress]。ToString();
但此代码返回null。如何在app_code中访问会话值。请帮忙完成这项任务。
In APP_CODE
logic.cs:-
string mac2 = System.Web.HttpContext.Current.Session["macAddress"].ToString();
but this code return null. how to access session value in app_code. Kindly help for this task.
推荐答案
System.Web.HttpContext.Current.Session["VariableName"]
在获得会话价值之前,你必须设置它。
在尝试获取之前,您没有设置它或会话过期。
Before getting session value you must set it .
Either you are not setting it or your session expires before you trying to get it.
<sessionstate timeout="40" />
如果您使用的是表单身份验证,则必须调整此属性:
If you are using Forms authentication, You have to adjust this attribute:
<authentication mode="Forms">
<forms timeout="40" />
</authentication>
这篇关于如何在asp.net中的app_Code层(逻辑文件)中使用会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!