如何在asp.net中的app_Code层(逻辑文件)中使用会话值 [英] how to use session value in app_Code layer (logic file) in asp.net

查看:76
本文介绍了如何在asp.net中的app_Code层(逻辑文件)中使用会话值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这里我在正常页面中使用会话值。现在我想传入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.

推荐答案

你好



你一定是遗失了什么



会话价值将通过



Hi

You must be missing something

Session values will be available through

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.


默认情况下,ASP.NET中的会话超时为20分钟。要增加超时或到期,您必须在web.config文件中更改SessionState的超时属性



By default, Session timeouts are 20 minutes in ASP.NET. To increase the timeout or expiry you have to change the timeout attribute for SessionState in the web.config file

<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层(逻辑文件)中使用会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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