View Single Post
  #3 (permalink)  
Old January 25th, 2009, 01:02 PM
Lee Dumond's Avatar
Lee Dumond Lee Dumond is offline
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by Spider View Post
I don't know where the source I am picking the user name up from needs to be - for example from a session, cookie, form, profile.

I can get it to work in the test; (when I use the 'profile' value as 'username') but this is because I am typing in the user name - I need it to recognise the name of the logged in user as opposed to have them type it each time.
Keep in mind that the current user identity is always stored in the current HttpContext. Therefore, from a page, you can always use this:

string userName = Context.User.Identity.Name;

If the current user is not logged in, this value will be an empty string.

I think this is a little easier than Imar's suggestion, as it doesn't require you to use the static methods of Membership, or create a MembershipUser. It also works if you are using Windows authentication instead of the ASP.NET Forms authentication database stuff.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}