Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Is your reason for this to save a database call everytime you need the UserId? If so, when I'm using the ASP.NET MembershipProvider, I usually either do a custom provider that allows me to cache that call, or a utility method that I can cache.</p> <p>If you're thinking of putting it in the Profile, I don't see much reason for doing so, especially as it also will still require a database call and unless you are using a custom profile provider there, it has the added processing of parsing out the UserId.</p> <p>If you're wondering why they did not implement a GetUserId method, it's simply because you're not always guaranteed that that user id will be a GUID as in the included provider.</p> <p>EDIT:</p> <p>See <a href="http://weblogs.asp.net/scottgu/archive/2006/04/13/442772.aspx" rel="noreferrer">ScottGu's article on providers</a> which provides a <a href="http://download.microsoft.com/download/a/b/3/ab3c284b-dc9a-473d-b7e3-33bacfcc8e98/ProviderToolkitSamples.msi" rel="noreferrer">link to downloading the actual source code for i.e. SqlMembershipProvider</a>. </p> <p>But the simplest thing to do really is a GetUserId() method in your user object, or utility class, where you get the UserId from cache/session if there, otherwise hit the database, cache it by username (or store in session), and return it.</p> <p>For something more to consider (but be very careful because of cookie size restrictions): <a href="http://www.eggheadcafe.com/tutorials/aspnet/33d4018a-03cf-48aa-9b68-82ba27aa6af9/forms-auth-membership-r.aspx" rel="noreferrer">Forms Auth: Membership, Roles and Profile with no Providers and no Session</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload