Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store info over multiple layers (DNA)

Status
Not open for further replies.

evoroel

IS-IT--Management
Jun 23, 2003
39
0
0
BE
Hi all

I'm working on a webbased hardware management system. I use ASP.Net for the presentation layer, C# classes for the business layer and SQL server (Stored Procedures) for the database layer.

I'm able to store information in the Session. I can use this info only on ASP.Net.

Is there a way to get the session to work in the business and database layer.

An Example:

On a click event in an ASP.Net page:

Session["UserName"] = textUserName.Text;
logging logger = new logging();


In the logging class:

logme(Session["UserName"]);


But the Session object gives a reference error. How can I get this to work (don't have to be using sessions)?

I would like to have an array where I can store user specific information which I can use on all the layers as long as the session is running.

Hope I'm a bit clear what my problem is.
evoRoel
 
AFAIK, the ASP.NET session object is only available to the page and the code-behind. If you want to use it in deeper layers you would have to have a "using" statement to make it accessible.

But honestly, I wouldn't bother -- the middleware shouldn't know anything about it. You would be better off in the long run writing your own Session class, and setting the values you need into it in the code-behind before calling the middle tier. You'll have more control over the contents, and you'll be able to use it anywhere you want in the middle tier and the database tier by setting a reference.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Hi Chiph

Tnx for the info. I agree with you that a custom session class is better.

But how do I retain the class between 2 ASP pages?

All classes in the middle tier are closed after the first page is finished.

I could use a static class but these are static for all users and I need to store user specific information.

Any thoughts?
evoRoel
 
You instantiate the custom session object in the code-behind (which implies that the session object needs to be in it's own assembly).

You then pass it through your various layers as a parameter. Which seems like a lot of work, but it can be made to work for you -- if you need to supply values on a per-user basis, you can set up a collection in your session class to hold them (for example, permission values). When the user signs on, the session object is populated with their permissions. Afterwards, it gets passed everywhere so you don't need to look them up again, saving you time.

The thing to watch out for is it becoming a "kitchen sink" kind of object. Don't put anything in there unless it directly pertains to the user's session. If it doesn't belong, pass it as it's own parameter to the method you're calling.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Actualy, I'm looking for a way to prevent passing the session assembly.

I guess I have to look into static assemblies again.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top