Membership.GetUser(), is there a better way?

N

Nightcrawler

I recently started to use MemberShip, Roles, and User to build a
portal site in asp.net 2.0. I currently have set the web.config to
only store registered users in the database. I don't want to pollute
the aspnet_Users with anonymous users.

I have two questions:

1. When a user gets to one of my aspx pages I would like to find out
if the user is logged in. I am currently doing it this way:

MembershipUser membershipUser = Membership.GetUser();

if (membershipUser != null)
{
... some code
}
else
{
... some code
}


Is there a better way? I feel that everytime I do this it will have to
pull the user from the database. It sounds like an expensive way to
see if the user is logged in or not. Does the built in membership/
roles engine in asp.net 2.0 support storing this information in a
cookie? What is the most efficient way available?

2. My website contains a profile page that any logged in user can see
using LoginView. However, I want to find out if the user viewing the
profile is the same user that created the profile and offer a couple
of extra buttons. Is there a clean and resource efficient way of doing
this?

Thanks in advance.
 
N

Nightcrawler

Firstof all, this is not really a C# Language question - it belongs in the
ASP.NET group.

If your Membership and optional Role and Profile providers are set up in the
normal way with Forms Authentication, you should only need to do:

if(User.IsAuthenticated)
{
// your cool code here}

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com












- Show quoted text -

I only have the User.IsInRole availability. Am I missing something?
 

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