473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

web pages, instantiated classes, and parents

Not sure if I'm posting this in the right spot, but....

Lets say i have a class for data access that gets instantiated on each page
in a web application ( .Net 1.1 )

From inside that class, how can I get a reference to the page that
instantiated it?

I'm assuming there is something in system.reflection, but I'm not familiar
with reflection enough to figure out what to use.
Nov 17 '06 #1
8 1195
You don't. You'd have to pass that in as a parameter
in the constructor (or some method in the class).

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"pirho" <pi***@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Not sure if I'm posting this in the right spot, but....

Lets say i have a class for data access that gets instantiated on each
page
in a web application ( .Net 1.1 )

From inside that class, how can I get a reference to the page that
instantiated it?

I'm assuming there is something in system.reflection, but I'm not familiar
with reflection enough to figure out what to use.

Nov 17 '06 #2
There is no way to get it?

I can change the New to get the information, but I didn't really want to
have to change all the pages that instantiate the class.

"Robbe Morris [C# MVP]" wrote:
You don't. You'd have to pass that in as a parameter
in the constructor (or some method in the class).

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"pirho" <pi***@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Not sure if I'm posting this in the right spot, but....

Lets say i have a class for data access that gets instantiated on each
page
in a web application ( .Net 1.1 )

From inside that class, how can I get a reference to the page that
instantiated it?

I'm assuming there is something in system.reflection, but I'm not familiar
with reflection enough to figure out what to use.


Nov 17 '06 #3
You can pass the reference to the page in a session variable and access it
from a class as HttpContext.Current.Session["myPage"].

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"pirho" <pi***@discussions.microsoft.comwrote in message
news:F7**********************************@microsof t.com...
There is no way to get it?

I can change the New to get the information, but I didn't really want to
have to change all the pages that instantiate the class.

"Robbe Morris [C# MVP]" wrote:
>You don't. You'd have to pass that in as a parameter
in the constructor (or some method in the class).

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"pirho" <pi***@discussions.microsoft.comwrote in message
news:61**********************************@microso ft.com...
Not sure if I'm posting this in the right spot, but....

Lets say i have a class for data access that gets instantiated on each
page
in a web application ( .Net 1.1 )

From inside that class, how can I get a reference to the page that
instantiated it?

I'm assuming there is something in system.reflection, but I'm not
familiar
with reflection enough to figure out what to use.



Nov 19 '06 #4
Yes, could definitely do this but it would be bad design
practice to incorporate the HttpContext in a data access layer
class. What happens when you need to deploy that data access
layer in a non-web environment?

The bigger question for me is what value is there to telling
the data access layer which class instantiated it or in what
environment it was called from. Typically, you'd write
separate methods to perform this sort of logging
as an http handler or via some other method triggered
from the user interface.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u4****************@TK2MSFTNGP06.phx.gbl...
You can pass the reference to the page in a session variable and access it
from a class as HttpContext.Current.Session["myPage"].

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"pirho" <pi***@discussions.microsoft.comwrote in message
news:F7**********************************@microsof t.com...
>There is no way to get it?

I can change the New to get the information, but I didn't really want to
have to change all the pages that instantiate the class.

"Robbe Morris [C# MVP]" wrote:
>>You don't. You'd have to pass that in as a parameter
in the constructor (or some method in the class).

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"pirho" <pi***@discussions.microsoft.comwrote in message
news:61**********************************@micros oft.com...
Not sure if I'm posting this in the right spot, but....

Lets say i have a class for data access that gets instantiated on each
page
in a web application ( .Net 1.1 )

From inside that class, how can I get a reference to the page that
instantiated it?

I'm assuming there is something in system.reflection, but I'm not
familiar
with reflection enough to figure out what to use.


Nov 19 '06 #5
Well, you can almost always tell if you are in a web application by checking
HttpContext.Current on null.

I am not going to disagree with you on your points. I just think we should
sometimes give directions how to achieve a goal in a certain way even if we
would not have taken this way ourselves.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Robbe Morris [C# MVP]" <jo*****@joe.comwrote in message
news:uq**************@TK2MSFTNGP03.phx.gbl...
Yes, could definitely do this but it would be bad design
practice to incorporate the HttpContext in a data access layer
class. What happens when you need to deploy that data access
layer in a non-web environment?

The bigger question for me is what value is there to telling
the data access layer which class instantiated it or in what
environment it was called from. Typically, you'd write
separate methods to perform this sort of logging
as an http handler or via some other method triggered
from the user interface.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u4****************@TK2MSFTNGP06.phx.gbl...
>You can pass the reference to the page in a session variable and access
it from a class as HttpContext.Current.Session["myPage"].

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"pirho" <pi***@discussions.microsoft.comwrote in message
news:F7**********************************@microso ft.com...
>>There is no way to get it?

I can change the New to get the information, but I didn't really want to
have to change all the pages that instantiate the class.

"Robbe Morris [C# MVP]" wrote:

You don't. You'd have to pass that in as a parameter
in the constructor (or some method in the class).

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"pirho" <pi***@discussions.microsoft.comwrote in message
news:61**********************************@micro soft.com...
Not sure if I'm posting this in the right spot, but....

Lets say i have a class for data access that gets instantiated on
each
page
in a web application ( .Net 1.1 )

From inside that class, how can I get a reference to the page that
instantiated it?

I'm assuming there is something in system.reflection, but I'm not
familiar
with reflection enough to figure out what to use.



Nov 20 '06 #6
ok, maybe some more information.

This is an existing application.

It is a web based catalog editor for an etailer.

When it was written, there were perhaps 5 employees in the company. Over a
hundred now.

There were perhaps 2 people who initially entered data into the catalog.
I'm not sure how many there are now, must over 10 people. There are about to
be another 10 from a data entry company.

There was no authorization. There is now as I just finished that portion.

There is no auditing, that is what I'm working on now.

I've decided to binary serialize any business objects to store them in SQL
image fields, got that working ( at least until those objects change, but
I'll worry about that later. Most of the time, the auditing needs will be "
what happened in the last two days" )

Now, security is done through a "BasePage" that checks whether a person can
see the current page.
All pages inherit from BasePage.

All pages instantiate a DAL object, and call methods to do any SQL access.

I need to audit any Insert, Delete, Change actions.
Part of the audit is Who did the change, which the BasePage has a property
for.
( Using integrated auth )

Thus, I need access to the Calling/Instantiating object, not for the Page
context, but for what the page object contains.

If I really MUST change all the calls, well, I'll figure out some non-tying
way to do it, but I didn't want to find and change them all because this
WOULD tie my DAL to the pages.

There is no way to do this in 1.1?

Cripes, I hope they put it in for 2.0 I'll have to go look.

"Eliyahu Goldin" wrote:
Well, you can almost always tell if you are in a web application by checking
HttpContext.Current on null.

I am not going to disagree with you on your points. I just think we should
sometimes give directions how to achieve a goal in a certain way even if we
would not have taken this way ourselves.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Robbe Morris [C# MVP]" <jo*****@joe.comwrote in message
news:uq**************@TK2MSFTNGP03.phx.gbl...
Yes, could definitely do this but it would be bad design
practice to incorporate the HttpContext in a data access layer
class. What happens when you need to deploy that data access
layer in a non-web environment?

The bigger question for me is what value is there to telling
the data access layer which class instantiated it or in what
environment it was called from. Typically, you'd write
separate methods to perform this sort of logging
as an http handler or via some other method triggered
from the user interface.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u4****************@TK2MSFTNGP06.phx.gbl...
You can pass the reference to the page in a session variable and access
it from a class as HttpContext.Current.Session["myPage"].

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"pirho" <pi***@discussions.microsoft.comwrote in message
news:F7**********************************@microsof t.com...
There is no way to get it?

I can change the New to get the information, but I didn't really want to
have to change all the pages that instantiate the class.

"Robbe Morris [C# MVP]" wrote:

You don't. You'd have to pass that in as a parameter
in the constructor (or some method in the class).

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"pirho" <pi***@discussions.microsoft.comwrote in message
news:61**********************************@micros oft.com...
Not sure if I'm posting this in the right spot, but....

Lets say i have a class for data access that gets instantiated on
each
page
in a web application ( .Net 1.1 )

From inside that class, how can I get a reference to the page that
instantiated it?

I'm assuming there is something in system.reflection, but I'm not
familiar
with reflection enough to figure out what to use.




Nov 20 '06 #7
pirho wrote:
ok, maybe some more information.

This is an existing application.

It is a web based catalog editor for an etailer.

When it was written, there were perhaps 5 employees in the company. Over a
hundred now.

There were perhaps 2 people who initially entered data into the catalog.
I'm not sure how many there are now, must over 10 people. There are about to
be another 10 from a data entry company.

There was no authorization. There is now as I just finished that portion.

There is no auditing, that is what I'm working on now.

I've decided to binary serialize any business objects to store them in SQL
image fields, got that working ( at least until those objects change, but
I'll worry about that later. Most of the time, the auditing needs will be "
what happened in the last two days" )

Now, security is done through a "BasePage" that checks whether a person can
see the current page.
All pages inherit from BasePage.

All pages instantiate a DAL object, and call methods to do any SQL access.

I need to audit any Insert, Delete, Change actions.
Part of the audit is Who did the change, which the BasePage has a property
for.
( Using integrated auth )

Thus, I need access to the Calling/Instantiating object, not for the Page
context, but for what the page object contains.

If I really MUST change all the calls, well, I'll figure out some non-tying
way to do it, but I didn't want to find and change them all because this
WOULD tie my DAL to the pages.
But the way you're trying to do it, the DAL has to have knowledge of
the class structure of your website, and surely a dependency in that
direction is even worse?
>
There is no way to do this in 1.1?

Cripes, I hope they put it in for 2.0 I'll have to go look.
I doubt you'll find anything. It's not something that *most* or even
*the majority* of developers will ever need, so why incur the
substantial overheads that would be required, just so that one or two
developers can write a bit less code.

My recommendation would be to create a new class in your DAL called
SecurityContext (or something similar). It contains each field which
the DAL needs for it's purposes. Then in your base page, you create a
function that returns an instance of SecurityContext, populated with
all the relevant details. Finally, you make the changes you need so
that all your calls into the DAL include a SecurityContext as a
parameter.

Yes, you'll have to change the existing code, but thereafter, if you
decide you need more details coming through to the DAL, you should only
have to change the SecurityContext class and the
GetDALSecurityContext() function in your base page.

And half of the rewriting should be quite quick - once you've edited
the functions within the DAL, a compile will find all of the locations
where there are calls into the DAL, and if you have ",
Me.GetDALSecurityContext()" in the clipboard, you can just click on
each error, press End, back-arrow, Ctrl-V, and move onto the next.

Damien

Nov 20 '06 #8
Well, the dal implements the class structure for CRUD.
Sure, there are some other methods, but I won't need to audit them.

I took the cheap route and simply added a property to the class, and I
changed the New function to require passing a string of the username.
If I need to pass more information later, I'll make a new class.

Oh, when I use the term dal for this application, it isn't a real dal
it is one monolithic class that simply contains methods to do the data access.

It already knows and uses the class structure of the website. I just didn't
want to make any more dependencies within the existing framework of what I
must work with.

Thanks for all the help to everyone though. It is much appreciated.

I guess I was looking for a shortcut to help me continue with a
"problematic" application.

"Damien" wrote:
pirho wrote:
ok, maybe some more information.

This is an existing application.

It is a web based catalog editor for an etailer.

When it was written, there were perhaps 5 employees in the company. Over a
hundred now.

There were perhaps 2 people who initially entered data into the catalog.
I'm not sure how many there are now, must over 10 people. There are about to
be another 10 from a data entry company.

There was no authorization. There is now as I just finished that portion.

There is no auditing, that is what I'm working on now.

I've decided to binary serialize any business objects to store them in SQL
image fields, got that working ( at least until those objects change, but
I'll worry about that later. Most of the time, the auditing needs will be "
what happened in the last two days" )

Now, security is done through a "BasePage" that checks whether a person can
see the current page.
All pages inherit from BasePage.

All pages instantiate a DAL object, and call methods to do any SQL access.

I need to audit any Insert, Delete, Change actions.
Part of the audit is Who did the change, which the BasePage has a property
for.
( Using integrated auth )

Thus, I need access to the Calling/Instantiating object, not for the Page
context, but for what the page object contains.

If I really MUST change all the calls, well, I'll figure out some non-tying
way to do it, but I didn't want to find and change them all because this
WOULD tie my DAL to the pages.

But the way you're trying to do it, the DAL has to have knowledge of
the class structure of your website, and surely a dependency in that
direction is even worse?

There is no way to do this in 1.1?

Cripes, I hope they put it in for 2.0 I'll have to go look.

I doubt you'll find anything. It's not something that *most* or even
*the majority* of developers will ever need, so why incur the
substantial overheads that would be required, just so that one or two
developers can write a bit less code.

My recommendation would be to create a new class in your DAL called
SecurityContext (or something similar). It contains each field which
the DAL needs for it's purposes. Then in your base page, you create a
function that returns an instance of SecurityContext, populated with
all the relevant details. Finally, you make the changes you need so
that all your calls into the DAL include a SecurityContext as a
parameter.

Yes, you'll have to change the existing code, but thereafter, if you
decide you need more details coming through to the DAL, you should only
have to change the SecurityContext class and the
GetDALSecurityContext() function in your base page.

And half of the rewriting should be quite quick - once you've edited
the functions within the DAL, a compile will find all of the locations
where there are calls into the DAL, and if you have ",
Me.GetDALSecurityContext()" in the clipboard, you can just click on
each error, press End, back-arrow, Ctrl-V, and move onto the next.

Damien

Nov 20 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dev | last post by:
Hello, Why an Abstract Base Class cannot be instantiated ? Does anybody know of the object construction internals ? What is the missing information that prevents the construction ? TIA....
2
by: big vinny | last post by:
Hi I've been writing some serializing functions to load/store classes into db tables. There appears to be 2 ways of doing it, 1) iterative, derived classes store their parent's data before...
5
by: Felix I. Wyss | last post by:
Good Afternoon, I recently noticed that some very simple methods of a template declared and used in a DLL library get inlined when used by the DLL itself, but not by other DLLs and EXEs. After...
3
by: Garth17 | last post by:
I'm trying to figure out a solution for sharing common properties and methods in all me .aspx and .ascx pages. In classic ASP I would use include directives. So far I have made 2 base classes...
5
by: Michael Herman \(Parallelspace\) | last post by:
1. What are some compelling solutions for using Master/Content pages with Web Pages? 2. If a content area has a web part zone with web parts, what is the user experience like when "editting" the...
4
by: Andrew | last post by:
I need to have a series of collection classes that inherit (I think) from each other. What is the best way to do this in .NET? In VB6 I had a series of collection classes each passing a reference...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
8
by: Brad Pears | last post by:
I want to check to see if a particular object exists using vb.net 2005. I have a class called clsContract. When the user clicks the 'New Contract' button, I want to check to see if a clsContract...
44
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.