.NETGURU
Page Inheritance in ASP.NET
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngreuse' list.


Jon Ceanfaglione
-- Moved from [aspngfreeforall] to [aspngreuse] by Clint Barton <Click here to reveal e-mail address> --

Hello all,

I have an ASP.Net application that uses a Base Page to inherit from. So
instead of having my forms inherit System.Web.UI.Page, I inherit my own Page
Class. In the base class for all my pages, I'd like to have the default
constructor for that page run a check on a session object to test for valid
sessions so that I don't have to put session checking code in every page. I
keep getting an error that:

     "Session state can only be used when enableSessionState is set to
true, either in a configuration file or in the Page directive"

However, I have this in my web.config file:

<pages
    buffer="true"
    enableSessionState="true"
    enableViewState="true"
    />

Is it possible to do this? I suspect not. If I can't use the default
constructor, how could I go about managing this?

Thanks.

Jon

__________________________________________________

The information contained in this communication is intended only for the use
of the recipient named above, and may be legally privileged, confidential
and exempt from disclosure under applicable law. If the reader of this
communication is not the intended recipient, you are hereby notified that
any dissemination, distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received this
communication in error, please re-send this communication to the sender and
delete the original communication and any copy of it from your computer
system. Thank you.

Reply to this message...
 
    
Little, Ambrose
Jon,

There is an application_beginrequest function in the global.asax that you
can use for code you want to execute at the beginning of every request. You
could also override the Init function on your base page class and do
checking there, I believe, or add an event handler for the page load event
on the base page class to check this.

--Ambrose

[Original message clipped]

******************************************************************************
The Company reserves the right to amend statements
made herein in the event of a mistake. Unless expressly
stated herein to the contrary, only agreements in writing signed
by an authorized officer of the Company may be enforced against it.
*******************************************************************************

Reply to this message...
 
    
Aditya Mahajan
i dont if Ambrose's reply helped finding the solution to the prob, but i faced the same prob yesterday, and here is how i resolved it:

string sMyVar = Context.Session["NUser"].ToString();

so if u want to access the session variable "NUser" in the base class, refer to it as
Context.Session["NUser"]

(Type your message here)

--------------------------------
From: Aditya Mahajan
Reply to this message...
 
 
System.Runtime.Remoting.Contexts.Context
System.Web.UI.Page




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification