473,398 Members | 2,368 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,398 software developers and data experts.

Sharing objects between Web and console

Are there are any best practices or guidance on how to share an object
between the Web world and the non?

Here's my situation: i have one object (a security profile containing
IPrincipal + some other stuff) that almost every other object in my system
uses (methods have role-based security). The object is specific to a user.
User A logs in, gets authenticated, his security profile gets shoved into
Session, each page he goes to retrieves it from Session, each object he calls
also retrieves it from Session, each object that object calls retrieves it
from Session and so on and so on

We are now writing batch processes. Every night the batch cycle calls an EXE
that does a bunch of stuff with the database (ex - a user's last day was
scheduled to be Friday, on Friday the employee termination code runs). This
app should use all our business objects. Which rely on an object (the
security profile) that's currently in Session state. So that ain't gonna work

i know i'm not the first person to run into something like this. So the
question is, how do i share objects between ASP.NET and non-ASP?

Here are my thoughts:

1. Use Thread.CurrentPrincipal. Both Web and non-Web apps have access to
this. Make my own security object implement IPrincipal and recast on
retrieve. Works great for WinForms, complete failure for ASP.NET. ASP.NET
wipes out the principal object on every page call and creates a new principal
containing only the user's name - no role data, nothing that was in the
security profile. So this won't work

2. Get the security profile from a class that can tell if it's a console or
ASP.NET app (don't know how but i'm sure it's possible). Have it pull from
Thread.CurrentPrincipal for console, Session for ASP.NET

3. Get user ID from Thread.CurrentPrincipal. Use that to relook up all the
security info every time it's needed (takes roughly 5 stored procedures calls
against two databases). Given that we use a lot of objects, this could lead
to a bunch of database calls

4. Manually pass the security profile from object to object and method to
method. Talk about ugly... Also not very secure, but then i'm thinking
nothing that uses Forms Authentication is likely to be

5. Make a facade the user can call, make every other class internal, have
the facade check credentials (via a database look up). This might be an issue

6. Beg you guys for advice

i've chosen option 6 :)
Jul 21 '05 #1
1 1532
Not sure but for now it looks like to me that the problem is that your
classes are explicitely fetching the object you need from a session variable
introducing then a dependency on the overall context of execution for these
classes (ie. they breaks in non ASP.NET applications).

You could :
- feeding class(es ?) with the object instead of letting them fetch the
object from their environment (by picking this one from a session variable)

If you need to pass this around, this is perhaps because of a problem in
your programming model. You could perhaps for example add a "context" object
to your programming model. This context would be shared by all security
related classes...

You could also approach this by using a "provider" whose purpose is to
provide those classes with the object you need. You'll have a provider for
ASP.NET and a provider for non ASP.NET applications...

Patrice

--

"baylor" <ba****@discussions.microsoft.com> a écrit dans le message de
news:77**********************************@microsof t.com...
Are there are any best practices or guidance on how to share an object
between the Web world and the non?

Here's my situation: i have one object (a security profile containing
IPrincipal + some other stuff) that almost every other object in my system
uses (methods have role-based security). The object is specific to a user.
User A logs in, gets authenticated, his security profile gets shoved into
Session, each page he goes to retrieves it from Session, each object he calls also retrieves it from Session, each object that object calls retrieves it
from Session and so on and so on

We are now writing batch processes. Every night the batch cycle calls an EXE that does a bunch of stuff with the database (ex - a user's last day was
scheduled to be Friday, on Friday the employee termination code runs). This app should use all our business objects. Which rely on an object (the
security profile) that's currently in Session state. So that ain't gonna work
i know i'm not the first person to run into something like this. So the
question is, how do i share objects between ASP.NET and non-ASP?

Here are my thoughts:

1. Use Thread.CurrentPrincipal. Both Web and non-Web apps have access to
this. Make my own security object implement IPrincipal and recast on
retrieve. Works great for WinForms, complete failure for ASP.NET. ASP.NET
wipes out the principal object on every page call and creates a new principal containing only the user's name - no role data, nothing that was in the
security profile. So this won't work

2. Get the security profile from a class that can tell if it's a console or ASP.NET app (don't know how but i'm sure it's possible). Have it pull from
Thread.CurrentPrincipal for console, Session for ASP.NET

3. Get user ID from Thread.CurrentPrincipal. Use that to relook up all the
security info every time it's needed (takes roughly 5 stored procedures calls against two databases). Given that we use a lot of objects, this could lead to a bunch of database calls

4. Manually pass the security profile from object to object and method to
method. Talk about ugly... Also not very secure, but then i'm thinking
nothing that uses Forms Authentication is likely to be

5. Make a facade the user can call, make every other class internal, have
the facade check credentials (via a database look up). This might be an issue
6. Beg you guys for advice

i've chosen option 6 :)

Jul 21 '05 #2

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

Similar topics

3
by: Alex | last post by:
Hi all, I want to write a "File sharing system". Is posssible with socket and thread create multisuer connection at the same time ? or is wrong my idea?? thanks
1
by: Dennis Gavrilov | last post by:
Hi, All! I have two questions: strategic and technical. Technical one first: I need to share an array of objects (implemented as hashes, having references to other objects and hashes, sharing...
42
by: Rigga | last post by:
Hi all, I am wondering why string's are not true objects?.... Let me explain... If i write the code Dim x1 as String = "veg" Dim x2 as String = "veg" If x1 = x2 then
0
by: Phl | last post by:
Hi, I have a console application and a web server which uses the same classes as the console application. Is there some way of sharing variables in these classes so that both the console app and...
3
by: Todd Gruben | last post by:
I am trying to send some encrypted data from a php application to be decoded in a .Net application. Both apps encode/decode a given string but generate different encrypted results. Anyone have...
1
by: baylor | last post by:
Are there are any best practices or guidance on how to share an object between the Web world and the non? Here's my situation: i have one object (a security profile containing IPrincipal + some...
8
by: antonyliu2002 | last post by:
We are extending a web application written in classic ASP long time ago. We will add more components to this web application in ASP.NET 2.0. To use the web application, our web users will have...
19
by: Zytan | last post by:
I want multiple instances of the same .exe to run and share the same data. I know they all can access the same file at the same time, no problem, but I'd like to have this data in RAM, which they...
45
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.