Asp.net上的会话帮助 [英] Session on Asp.net Help

查看:100
本文介绍了Asp.net上的会话帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作我的项目,我已经为其创建了一个2页母版和他的10个子页面。 1是For admin,另一个是For Application User。



登录后用户ID和他的名字必须传递给每个子页面。



我需要知道这个我可以将用户ID和名称传递给唯一的母版页,然后子页面可以从母版页访问这些变量。

I am Working on my Project, on Which i have Created a 2 Master Page and his 10 child pages for each. 1 is For admin and other One is For Application User.

Upon Login User id and his name has to pass on each child page.

I need to know this Can I pass the user id and name to the only master page and then child pages can access these variables from master page.

推荐答案

无论您在何处设置会话,它都可以在一个特定会话的所有页面中使用。
Wherever you set the Session, it would be available in all pages for one particular Session.


不必要。

Page类有一个User属性,其中包含用户的Priciple对象。

http://msdn.microsoft.com/en-us/library /system.web.ui.page.user(v=vs.110).aspx [ ^ ]



所以,在任何页面你都可以做

Unnecessary.
The Page class has a User property which contains the user's Priciple object.
see http://msdn.microsoft.com/en-us/library/system.web.ui.page.user(v=vs.110).aspx[^]

So, in any page you can do
var username = Page.Identity.Name;



使用用户名,您可以使用会员资格或Aspnet.Identity系统获取任何其他用户详细信息。



如果您使用的是AspNet.Identity,则用户可能会声明包含您需要的其他信息,从而消除需要进行可能访问数据库的调用。


Using the username, you can use the Membership or Aspnet.Identity system to get any other user details.

If you are using AspNet.Identity, the User may have Claims the contain the additional information you require, eliminating the need to make a call that potentially accesses the database.


这篇关于Asp.net上的会话帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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