如何访问会话瓦尔从基类在ASP.Net? [英] How can I access Session vars from Base class in ASP.Net?

查看:126
本文介绍了如何访问会话瓦尔从基类在ASP.Net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经到关于asp.net会话这个问题上运行。我创建一个ASP.Net Web应用程序。我创建了一个名为BasePage类,从System.Web.Ui.Page继承。这BasePage类是所谓的类型ActiveUser(我已经创建了自己的一类)的ActiveUser一个额外的成员System.Web.Ui.Page。在的BasePage的构造我设置成员的UI this.ui =(ActiveUser)会议[ActiveUser] ,这是一个会话VAR是previously设置。然而,当我跑我的项目,我的BasePage的构造得到了 HttpException this.ui =会话[ActiveUser] 。它告诉我在配置文件中,我已经检查,这是检查然而enableSessionState设置为true。不要任何人有关于如何解决这个任何想法?这将是非常美联社preciated。
感谢名单!

I've run in to a this problem regarding Sessions in asp.net. I'm creating an ASP.Net web application. I've created a class called BasePage that inherits from System.Web.Ui.Page. This BasePage class is a System.Web.Ui.Page with an additional member called ActiveUser of type ActiveUser (a class I've created of my own). In the constructor of BasePage I set the member ui to this.ui = (ActiveUser)Session["ActiveUser"], which is a session var that is previously set. However, when I run my project i get a HttpException in BasePage's constructor on this.ui = Session["ActiveUser"]. It tells me to check however enableSessionState is set to true in the config file, which I've checked that it is. Do anyone have any idéas on how to solve this one? It would be very much appreciated. Thanx!

推荐答案

只是好奇,为什么你的基本页面构造保存此?

Just curious why are you saving this in the base page constructor?

您不应该访问从构造会话,但Page_Init来代替。请参阅以下职位:

You shouldn't be accessing the session from the constructor but the Page_Init instead. See the following post:

<一个href=\"http://weblogs.asp.net/anasghanem/archive/2008/05/07/avoid-using-the-session-in-the-page-constructor.aspx\">http://weblogs.asp.net/anasghanem/archive/2008/05/07/avoid-using-the-session-in-the-page-constructor.aspx

实现页面功能时,为什么不能创建一个静态类/方法与功能抓住你所有的会话数据会话变量会在任何时候访问?我不明白你为什么会想复制此数据存储在你的基类。

The session variable will be accessible at any time when implementing the page functionality so why not create a static class / method with functionality to grab all your session data? I don't see why you would want to duplicate storage of this data in your base class.

您可能会想看看这个线程:
<一href=\"http://stackoverflow.com/questions/133236/asp-net-session\">http://stackoverflow.com/questions/133236/asp-net-session

You might want to check out this thread: http://stackoverflow.com/questions/133236/asp-net-session

这篇关于如何访问会话瓦尔从基类在ASP.Net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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