Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 30th, 2004, 12:09 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to flyin
Default HttpContext.Current.Cache used to store user info?

Has anyone looked at the release of Microsoft's .Net Forums? Now i was told by very wise men that storing user specific information within the Cache object wasn't recommended, but here is this Microsoft forums using the cache object to store user specific data!

they store it in the HttpContext.Current.Cache. This is not a special type of cache is it? because it seems that they store a user object within this cache and use it across the app. Any thoughts on this? Is this an answer to using th session object? thanks

Flyin

Reply With Quote
  #2 (permalink)  
Old March 30th, 2004, 08:18 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Can you show a part of the code that stores user specific data in the cache? Are you sure it's user specific data, not data about users that applies to all users (like the current number of logged on users, the latest sign up, etc)?

I find it hard to believe that they store user data in the cache, as the cache is available to everyone, and not to just one specific user.

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #3 (permalink)  
Old March 30th, 2004, 09:59 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to flyin
Default

        public static User GetUserInfo(String username, bool updateIsOnline) {
            string userKey = "UserInfo-" + username;

            // Attempt to return the user from Cache for users not online to save
            // us a trip to the database.
            if (updateIsOnline == false) {
                if (HttpContext.Current.Cache[userKey] != null)
                    return (User) HttpContext.Current.Cache[userKey];
            }

            // Let's not go to the database each time we need the user's info
            if (HttpContext.Current.Items[userKey] == null) {
                // Create Instance of the IDataProviderBase
                IDataProviderBase dp = DataProvider.Instance();

                User user = dp.GetUserInfo(username, updateIsOnline);

                // Hang on to the data for this request only
                HttpContext.Current.Items[userKey] = user;
            }

            // Do we need to add the user into the Cache
            if (updateIsOnline == false) {
                if (HttpContext.Current.Cache[userKey] == null)
                    HttpContext.Current.Cache.Insert(userKey, HttpContext.Current.Items[userKey], null, DateTime.Now.AddMinutes(1), TimeSpan.Zero);
            }

            return (User) HttpContext.Current.Items[userKey];
        }


This is a very common function used to return an instance of a User.

Reply With Quote
  #4 (permalink)  
Old March 30th, 2004, 10:24 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

From what I can see, this is not data for a user, but about a user.

This means that all users from the system can access the information about a specific user, rather like the Profile page here at P2P. The data is public, can be accessed by everyone, and "accidentally" deals with a user.

They are using this method to prevent looking up the user data every time it needs to be displayed, either in a thread, or in a profile page.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #5 (permalink)  
Old March 30th, 2004, 04:46 PM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to flyin
Default

Thanks for the input Imar, i'll look more into it to be sure. thanks

Reply With Quote
  #6 (permalink)  
Old March 30th, 2004, 06:56 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by flyin
 ...i was told by very wise men

Now now, watch out who you are calling 'wise'! I don't want to give anyone the idea that I know what I'm talking about. (Assuming you were referring to me from the other thread.) ;)

This is indeed interesting to see how MS does it.
Reply With Quote
  #7 (permalink)  
Old March 31st, 2004, 11:50 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to flyin
Default

Yes i was peter, was it obvious? :D Well, when i receive good info i like to give credit where credit is due.

Now for an interesting question.

When the user Explicitly sets their browser to block all first and third party cookies, this also makes the session level variables unusable as well don't they?

If so, User info will have to be server side won't they? Did someone say cache? Oh wait that was me. So, now to second question,

Has any of you written a helper class to forward Items that are stored in the cache to a classic asp app? I haven't tried it yet, but i doubt that an app written in classic asp can grab things from the cache object. Or can they? if so hey Give me a pointer! But if not, can you guys give me a clue as to how i would approach this little problem? thanks

Flyin

Reply With Quote
  #8 (permalink)  
Old April 3rd, 2004, 11:40 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Regarding the cookie issue: If the use blocks cookies, then you are out of luck. You won't get session maintenance at all. ASP.net does support cookieless operation. It embeds the session ID right in the URL after the first page request is made. The major dissadvantage to this is that copy and pasting links will create shared sessions. Frankly, the way I see it, if the user is going to block cookies, then they are greatly limiting what they can do online as any site that is more than static HTML output will use cookies.

Regardless of where the user information is stored, if the user has no cookies, then you won't be able to tell who they are at all. Even with the user info in a DB you have no identification method.

Classic ASP cannot access the cache. It doesn't even have a cache of its own. If you need to hand off data between application scopes (be them ASP.net to ASP.net or to ASP) you have a few options:

A) If the applications are on the same server root you can pass it thru cookies.
B) Pass it in querystrings though this could get bulky.
C) Build a database interface to this data and you then only need to pass some user indentification data so the other application can retrieve the data from the DB. This scenario essentially becomes interapplication state management with a simple page to page handoff.

I'm actually on a project that is doing what I described in (A) and (C). This project is actually a .net application with classic ASP pages in it. Because ASP and ASP.net run within two entirely separate runtime processes the theory is the same. The pages get the user ID from a cookie and load their respective data based on that from the DB.

Peter
------------------------------------------------------
Work smarter, not harder.
Reply With Quote
  #9 (permalink)  
Old April 4th, 2004, 03:14 AM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to flyin
Default

Thanks for the feedback peter. yes, as far as the cookieless users, i was thinking of writing a wrapper class and registering it in the GAC so that classic asp can call it with a simple
Server.CreateObect("MyNamespace.MyObject") that would encapsulate some of the cookieless functionality that .Net offers, but the more i think about it, the more i say screw the cookieless users because if you physically disabled cookies then you are not going to be able to access more sites that just mine, and if you are running some anti virus software that disables cookies for you, then i guess, oh well!!

I was thinking of writing an asp.net Cache wrapper that a legacy asp app can call to access user information, but then that overwrites the rules of storing only information in the cache that is accessable to all. But hey, I guess if you set strict expiration cache rules then it might be able to be done without effecting scalability too much. Just thoughts rambling.

Thanks again peter for the advice!

Flyin

Reply With Quote
  #10 (permalink)  
Old April 5th, 2004, 06:55 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Even if you write com callable wrappers (CCWs) that access the ASP.net HttpContext, you won't have any luck. The HttpContext is only accessible within the ASP.net runtime. If you are running in the scope of a classic ASP page, you aren't running in the context/scope of ASP.net so therefore cannot access the ASP.net page scope elements (cache, session, etc). There is no page instance from which to begin.

The cookieless functionality is core to the ASP.net runtime as well, so you can't use it in ASP for the same reason I explained above. You are running under the ASP runtime, not the ASP.net runtime. When you run in ASP.net cookieless mode, you get redirected to a URL that looks like this:

http://myserver/(znb2bm55khce0mmnbnvo2tr3)/mypage.aspx

If you then tried to go to
http://myserver/(znb2bm55khce0mmnbnvo2tr3)/myotherpage.asp
you get kicked back to that URL minus the session ID part. The extension of ASPX tells the server to process this request with the .net runtime and only that runtime knows how to parse and handle a request formed like that.

Your best bet if you need to work between ASP and ASP.net is to deal with data in a database. Potentially, you could create some object that handles this, and make that object visible to COM (there's an option in the project to "register for com"). Make a separate project for the needed object(s). Only that project will be registered for COM. Both .net and classic ASP will use that object for session/user management. Then all you need to worry about is handing back and forth some identifier for the session/user.

Peter
------------------------------------------------------
Work smarter, not harder.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How Can I Get the Name of the Current User? BrianWren Pro VB 6 0 March 27th, 2007 11:42 AM
Store info into a MySQL DB table KoRn PHP How-To 1 February 17th, 2004 03:00 PM
current user schockp Oracle 2 November 12th, 2003 06:18 AM
How do I store user login info to use in a form? lanctotd Classic ASP Basics 1 July 15th, 2003 08:06 PM



All times are GMT -4. The time now is 10:59 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.