Managed wrappers in ASP.NET Session

M

mirek

Hi,
Is it safe to put my objects that are managed c++ wrappers to the
session? I want to pass them from one page to the other in the session
object but I noticed strange (maybe it is ok) behaviour: sometimes
destructors from unmanaged classes (that are being wrapped by my
wrappers) are called when it's not needed.
Thanks in advance for any suggestions.

Regards,
mirek
 
N

Natty Gur

Hi,

Basically yes, but make sure that the unmanaged code isn't STA (probably
not if you wrote it in C++).

Personally I don’t like to use the session and in particular not to
store objects in the session. Can you share with us why you need to do
it ?
if you just need to pass them between pages that use transfer to
navigate between them you can use Context instead of session.

Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
M

mirek

Hi,
Thanks for your reply.

Natty said:
Personally I don’t like to use the session and in particular not to
store objects in the session. Can you share with us why you need to do
it ?
We've developed desktop appliaction in C++ (MFC) and fortunatelly we
separated code to have "business objects" classes in C++. Now we are
trying to implement web interface using ASP.NET and wrapping our
business classes to Managed C+ to be used on ASP.NET pages.

The first need was to store our user object (from business layer) in the
user's session so we could get user details, specific permission and
many other user's data on every page. Finally as there were problems I
was talking previuosly I've implemented global map where are put these
user objects (the session id is the key of this map) and it seems to
behave correct. (Also one advantage of this is that I am able to list
logged users or restrict that one user can only have one session.)

Another use of object in session is when I have multi page editing
(something like a wizard). On the first page I create my business
object, on submit I fill it with field values and pass it in the session
to the next page.
if you just need to pass them between pages that use transfer to
navigate between them you can use Context instead of session.
You mean Server.Transfer? It would be ok but I don't like that the url
isn't updated in the user's browser. It could be quite confusing for him
and refreshing a page isn't possible.


Reagrds,
mirek
 
N

Natty Gur

Hi,

I think that if you will break your program into 3 layer (Visualization,
Business logic, Data) you can prevent from saving object in the session.
in such application you will need just to save data of your users in the
session / application and you can use BL objects just to Process and
handle the data. You actually done it by using global map but you save
the data with the logic and I would recommend separating them. Behind
software design perspective of separating data from logic you can see
advantage of that approach in busy web application where thousands of
users hit the server. In that case there will be hundreds of Objects in
the map that increase the server memory usage. But if you will store
just the data in the session and separate object will be use to enforce
logic rules on that data you will end up with less objects and memory
usage.

Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
M

mirek

Natty said:
I think that if you will break your program into 3 layer (Visualization,
Business logic, Data) you can prevent from saving object in the session.
in such application you will need just to save data of your users in the
session / application and you can use BL objects just to Process and
handle the data. You actually done it by using global map but you save
the data with the logic and I would recommend separating them. Behind
software design perspective of separating data from logic you can see
advantage of that approach in busy web application where thousands of
users hit the server. In that case there will be hundreds of Objects in
the map that increase the server memory usage. But if you will store
just the data in the session and separate object will be use to enforce
logic rules on that data you will end up with less objects and memory
usage.
Yes, I know that the best would be make the layers you mentioned or
implement from scratch but unfortunatelly I haven't got enough time (who
has it? :)).
You said that you would store _data_ instead of objects in the session.
Could you explain it more or maybe small example. If I want to store
user data to the session so it would be accesible from every page, I'd
have to store in session following example values: permission="qwerty",
contacts=[ArrayList of contacts], last_login_date="28/01/2003", etc? I'd
say it's quite messy. The best would be "User" data object with
properties stored in the session on login, and then retrieved on every
page. Is my thinking OK? :)

Regards,
mirek
 
N

Natty Gur

Hi,

User data object is just fine :) (You can use DataTable) as long as you
take in account the memory consequences of storing object that consume X
bytes * Y users.

Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top