在主页面上存储和检索会话 [英] Storing and Retrieving Session to/from master page

查看:52
本文介绍了在主页面上存储和检索会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想询问如何在主页面中存储和检索会话。说,我有一个登录页面。在验证时,登录页面将数据(从数据库)存储到母版页,然后内容页面可以访问存储在母版页中的会话。任何样本代码?



[更新]这是一个场景。在登录页面中,用户被分类到权限。用户类型[a],[b],[c]。在母版页中,有3种不同的div菜单。 div菜单仅授予以下用户类型:



[a] - div菜单1

[b] - div菜单2

[c] - div菜单1,2,3



因为主页面包含所有div菜单,我怎么能禁用所有其他菜单菜单根据权限。

I just want to ask how to store and retrieve session to/from master page. say, i have a login page. upon validation, login page stores a data (from database) to master page, and then content pages can access the session stored in master page. any sample codes?

[updates] Here's the scenario. in login page, users are being sorted to permissions. user types [a], [b], [c]. in master page, there are 3 different div menus. the div menus are only granted to the following user types:

[a] - div menu 1
[b] - div menu 2
[c] - div menus 1, 2, 3

since the master page contains all div menus, how can i disable all other menus according to permissions.

推荐答案

会话未存储在您的母版页中,它存储在服务器的内存中。因此,任何页面都可以访问它。



要在会话中存储信息,请使用

Session is not stored in your master page, it is stored in memory on the server. Therefore, any page can access it.

To store information in the Session use
Session["SomeVariable"] = "SomeValue";





并从会话中获取数据使用



and to get data from the Session use

String someValue = Session["SomeVariable"];


会话可以在任何地方设置,可以在应用程序的任何地方访问。



因此,如果您在母版页中设置会话,也可以从内容页面访问它。

没有限制和限制。
Session can be set anywhere and can be accessed anywhere in application.

So, if you set the Session in Master Page, it can also be accessed from Content page.
There are no restriction and limitations.


以下代码用于存储会话值:



Following code is used for storing a value to session:

//Storing yourValue in Session
Session["yourValue"] = textboxUserName.Text;

Now, let see how we can retrieve values from Session

//Check weather session variable null or not
if (Session["yourValue"] != null)
{
//Retrieving yourValue from Session
label1.Text = "Welcome : " + Session["yourValue"];
}
else
{
//Do Something else
}





以下示例显示了如何存储一个DataSetin会话:





Following Example shows how to store a DataSetin session:

//Storing dataset on Session
Session["DataSet"] = _dataSetObject;





以下代码显示了我们如何从会话中检索该值:





and following code shows how we can retrieve that value from the session:

//Check weather session variable null or not
if (Session["DataSet"] != null)
{
//Retrieving value from Session
DataSet _ds= (DataSet)Session["DataSet"];
}
else
{
//Do Something else
}


这篇关于在主页面上存储和检索会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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