473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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.

Jul 16 '07 #1
2 2373
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

"Nightcrawler" wrote:
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.

Jul 16 '07 #2
On Jul 16, 10:36 am, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
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

"Nightcrawler" wrote:
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.- Hide quoted text -

- Show quoted text -
I only have the User.IsInRole availability. Am I missing something?

Jul 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mrhicks | last post by:
Hello all, I have a question regarding efficeny and how to find the best approach when trying to find flag with in a structure of bit fields. I have several structures which look similar to ...
3
by: baibaichen | last post by:
hi i want to output strings with indent space, the code looks like: std::set<std::string> files; std::set<std::string> iterator b = files.begin(); std::set<std::string> iterator e =...
0
by: Ben | last post by:
Hi - which of these two methods is preferred to determine the username of the current user? Ben
2
by: Jav | last post by:
I need to get at the ProviderUserKey of the logged in user. I would have thought that I could do something like: Dim u As MembershipUser = Membership.GetUser Dim ProvKey as Guid =...
0
by: Ja NE | last post by:
I would like to offer my registered users to have very short uri for their pages in our comunity site, so I have enabled wildcard dns *.bellay.com. and added virtaul host for it. (I'm testing this...
3
by: Nightcrawler | last post by:
Hi, I have a blog in my application that any registered user can post to (I am using Microsoft's Memberships and Profiles for this). When I show the blog entries in a datalist I also want to...
0
by: sanju | last post by:
Hi, I have a problem with Lastactivitydate . It doesnt update with Membership.GetUser() method in production server.but its working fine in local PC , all the settings and web.config elements...
2
by: Florian Paulus | last post by:
Hello group, i'm trying to load some additionally stored information to a user at login time. That data is self created and stored in an sql database. I hooked in the login control...
0
by: Jeff | last post by:
Hi asp.net 2.0 I wonder what's the best technigue to get the handle to the current loggedin user Is it: HttpContext.Current.User Or is it
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.