how to transfer a class from 1 app to another

J

Jason Shohet

Perhaps an asp.net question but involves c# classes so I'd rather ask this
here. Here goes:

Lets say I have an asp.net app called Logon. When a user logs on in Logon,
a User class is populated with his / her name, department etc. After the
user has logged in I present him with a page that lets him go to other
websites -- app1 & app2.

The problem is when he is redirected over to app1 or app2, I want that User
class to come with him! Because the User class will tell me what kind of
user he is, permissions etc. I don't want to make him log on again. I want
to look at the User class that was populated in the previous application,
Logon. I just don't know the best way to transfer a class from 1 asp.net
application to another, or if there's a better architecture for this kind of
thing.
Basically if someone logs on thru our Logon app, every other app we redirect
him to should be able to interrogate the User class to find out what this
user can do in the application.

TY for any advice
Jason Shohet
 
N

Nicholas Paldino [.NET/C# MVP]

Jason,

First, you will need to have each app reference the same implementation
of the User class. This way, when you serialize it (whatever method you
use), you will have the same code running.

Once you do that, you can do a number of things. I think the easiest to
do would be to serialize the instance and then send that to the other app
somehow. You can post this information in a form, or you can store the
serialized content to a database, and then send a pointer to the other app
indicating where in the DB you can find it.

Hope this helps.
 
D

David Browne

Jason Shohet said:
Perhaps an asp.net question but involves c# classes so I'd rather ask this
here. Here goes:

Lets say I have an asp.net app called Logon. When a user logs on in Logon,
a User class is populated with his / her name, department etc. After the
user has logged in I present him with a page that lets him go to other
websites -- app1 & app2.

The problem is when he is redirected over to app1 or app2, I want that User
class to come with him! Because the User class will tell me what kind of
user he is, permissions etc. I don't want to make him log on again. I want
to look at the User class that was populated in the previous application,
Logon. I just don't know the best way to transfer a class from 1 asp.net
application to another, or if there's a better architecture for this kind of
thing.
Basically if someone logs on thru our Logon app, every other app we redirect
him to should be able to interrogate the User class to find out what this
user can do in the application.

Each asp.net app is in its own AppDomain, and so you will need to stick your
user object somewhere outside each AppDomain, and retrieve it from the other
AppDomain.

You could:
-Create a new asp.net app just for the User objects there and access them
through remoting or HTTP. EG: Server-side post to
http://localhost/LoginApp/GetUserInfo.aspx?sessionID=123546789
-Store it in a database or a file
-Store it in a Memory Mapped file using the Caching Application Block for
..NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/CachingBlock.asp

David
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Jason,

Nicholas and David pretty much said how to do it, but as I was reading your
post I think that you are working on a intranet environment, if it's so try
to explore the possibility of using windows authentication, if you can use
it's better for you and for your users as they don't have to login and you
dont have to keep a reference to the logged user.


Cheers,
 
J

Jason Shohet

Thanks to you, Nicholas & David. I am OK with the first & 3rd suggestions,
and I'll try for the 3rd (windows auth.) first since its easier. But I have
never done what David suggested:

-Create a new asp.net app just for the User objects there and access them
through HTTP (or remoting, i suppose, in the c/s world). David gave the
example of a form (http) POST:
http://localhost/LoginApp/GetUserInfo.aspx?sessionID=123546789

I am not sure how this works above. I am guessing that David is suggesting
that the user actually goes to the 2nd application first. There in
page_load it calls the LoginApp in an http request (above), but how? Can't
be a hyperlink :) although above it looks like one. And how do i get that
sessionID, and how does LoginApp return back the employee class object
(which I'll need in that 2nd application).

TY for all the help! -- Jason Shohet
 
D

David Browne

Jason Shohet said:
Thanks to you, Nicholas & David. I am OK with the first & 3rd suggestions,
and I'll try for the 3rd (windows auth.) first since its easier. But I have
never done what David suggested:

-Create a new asp.net app just for the User objects there and access them
through HTTP (or remoting, i suppose, in the c/s world). David gave the
example of a form (http) POST:
http://localhost/LoginApp/GetUserInfo.aspx?sessionID=123546789

I am not sure how this works above. I am guessing that David is suggesting
that the user actually goes to the 2nd application first. There in
page_load it calls the LoginApp in an http request (above), but how? Can't
be a hyperlink :) although above it looks like one. And how do i get that
sessionID, and how does LoginApp return back the employee class object
(which I'll need in that 2nd application).

It would work basically like this:

User starts at LoginApp/Login.aspx. This page validates the user's
credentials and creates a session for the user, and stores the user data in
a Application-scope hashtable keyed by a sessionID. Then the user clicks
over to another application. But LoginApp adds a session id to the url for
the other app. Say App2/Start.aspx?sessionID=123546789.

App2/Start.aspx in it's form_load uses the sessionID and and the
HTTPWebRequest class to hit a private page or even a simple WebService
hosted in LoginApp, which returns the user data (username and password) to
App2.

David
 
J

Jason Shohet

Fascinating. Does this method (passing a sessionID from 1 app to another)
have advantages / disadvantages over serializing the entire class & passing
it over -- the method that Nicholas outlined.

Also, if the first application is no longer there since we redirected them
with a URL, is that 123456789 session still in existence? In other words if
the 2nd app calls a page now in the Login app, how can it get a hold of that
prior session after we had already redirected away from that first app, in
order to get to the 2nd ;)
TY for enlightening the blind
Jason Shohet
 
D

David Browne

Jason Shohet said:
Fascinating. Does this method (passing a sessionID from 1 app to another)
have advantages / disadvantages over serializing the entire class & passing
it over -- the method that Nicholas outlined.

No.

Also, if the first application is no longer there since we redirected them
with a URL, is that 123456789 session still in existence? In other words if
the 2nd app calls a page now in the Login app, how can it get a hold of that
prior session after we had already redirected away from that first app, in
order to get to the 2nd ;)


You would be in charge of storing the user info in a static or
application-scope HashTable, keyed by the session ID.

David
 
J

Jason Shohet

Thanks for the help Dave.
I think we're going to go with the serialization approach because then we
don't have to be in the business of storing sessions in a db table. We'll
serialize the class, & send it over in a POST.
The 2nd app can just reconstitute the class from the serialized string...
well at least it sounds good in theory :) !
Rgds
Jason Shohet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top