Finding Email address in a Profile

G

Guest

I just started using The Login Objects and the CreateUserWizard creates a
number of fields including Email address and i cant figure out how to
reference it: intellisense tells me that Profile.Username is available, as
are all of my customised fieldnames - but where would i find the Email
Address?? All i want to do is assign the email address of the logged in user
to a string

Regards

Owen
 
K

Ken Cox [Microsoft MVP]

Hi Owen,

I think you'll find the email address is stored in a different place in the
database. You can get at it using one of the built-in views.

Here's some code that might get you pointed in the right direction. It feels
like a hack, so please post any improvements? See the inline comments for
details.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET[

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
' By Ken Cox [Microsoft MVP]
' August 24, 2006
' Please improve on this hack! --kc
' Declare the dataview, sqldatasource
' and connection
Dim dv As New Data.DataView
Dim sqldsrc As New SqlDataSource
Dim connectionStrings As _
ConnectionStringSettingsCollection = _
System.Web.Configuration. _
WebConfigurationManager.ConnectionStrings
' Set the select command to use the built-in view
' and narrow the view down to the username
sqldsrc.SelectCommand = "SELECT Email FROM " & _
"vw_aspnet_MembershipUsers WHERE (UserName = 'kencox')"
' Make sure we are treating it as a text
' query rather than as a stored procedure
sqldsrc.SelectCommandType = SqlDataSourceCommandType.Text
' Tell the sqldatasource to return a dataset or datatable
sqldsrc.DataSourceMode = SqlDataSourceMode.DataSet
' Set the ID for good form
sqldsrc.ID = "sqldatasource1"
' Fetch the connection string from the web.config
sqldsrc.ConnectionString = connectionStrings.Item _
("ASPNETDBConnectionString").ConnectionString
' Get the retrieved data into the dataview by
' calling the Select method with no arguments
dv = sqldsrc.Select(DataSourceSelectArguments.Empty)
' Put the retrieved value from the "email" column
' into the label
Label1.Text = dv.Table.DefaultView(0).Item("email")
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Get the email address of a Membership row</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<p>
&nbsp;<asp:label id="Label1"
runat="server"></asp:label></p>
&nbsp;</div>
</div>
</form>
</body>
</html>
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top