tags:

views:

40

answers:

1

hi, i'm using forms based authentication within my aspnet (c#) website. At the log in page i'm capturing username, password and email. the email addressed is stored within the membership table. now on a new page, i'd just like to display the users' email address so they update it as well as another boolean field. i've tried using a gridview but i can't figure out how to modify the query so it only reveals the current logged in user. thanks!

A: 

Hi,

Since you're using Membership controls, you could to this.

string userEmail = Membership.GetUser().Email;

If you don't pass a parameter to GetUser(), it will find the details of the currently logged in user.

MSDN doc for Email property

MSDN doc for GetUser method

keyboardP
ok thanks, so i placed that code in my code behind file. then to call the data in my aspx page, i just place `<form id="form1" runat="server">Welcome <b><%=userEmail%></b>. </form>` correct?
PW2
Yes, that should work. You might want to look into caching the email string instead of polling the database on every call. A few methods http://www.4guysfromrolla.com/articles/022802-1.aspx
keyboardP
i'm getting the error, "useremail" does not exist in current context.
PW2
Did you copy and paste my code above? The code is case-sensitive, so it should be `userEmail`. If that's not it, then make sure you rebuild your project before running it.
keyboardP
i could not get this to work. sorry, i'm a newbie :/
PW2
Add a label control, which you can then set from the codebehind using myLabel.Text = userEmail. For an example, check the Email property link I gave in the answer. Look at how they've coded it.
keyboardP
hi, i got the code running from the "msdn email property" is there a way to set that code to display on the current user?
PW2
hey, thanks a lot for yout help. i'm posting another question to expand on my question.
PW2