By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,929 Members | 634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,929 IT Pros & Developers. It's quick & easy.

Accessing membership UserId programmatically?

P: n/a
After a user logs in (ASP.NET 2.0 membership/roles), how do I
programmatically access their UserId and other information stored in
the ASP.NET database structure? A user may login at Login.aspx and
then they are redirected to somepage.aspx. somepage.aspx doesn't have
a reference to the login object and can't access UserId.

Also, are there any issues with changing the UserId column from a
uniqueidentifier to an integer IDENT?

Thanks.

Jan 27 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a

All of the membership services can be accessed programmatically via
System.Web.Security.Membership class.

I would not recommend changing the database schema that MS uses for
membership info. My gut feeling is that would be bad.

Jason Vermillion

"perplexed" wrote:
After a user logs in (ASP.NET 2.0 membership/roles), how do I
programmatically access their UserId and other information stored in
the ASP.NET database structure? A user may login at Login.aspx and
then they are redirected to somepage.aspx. somepage.aspx doesn't have
a reference to the login object and can't access UserId.

Also, are there any issues with changing the UserId column from a
uniqueidentifier to an integer IDENT?

Thanks.

Jan 28 '07 #2

P: n/a
Thanks. I'd like to display a more friendly userid. Do you know of a
way I can generate one without disturbing the membership/roles
database schema?

Jan 28 '07 #3

P: n/a
Add a column to the database and display that.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"perplexed" <jo***@bigstring.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
Thanks. I'd like to display a more friendly userid. Do you know of a
way I can generate one without disturbing the membership/roles
database schema?

Jan 28 '07 #4

P: n/a


On Jan 27, 6:22 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
Add a column to the database and display that.
Juan, that's right but I guess I was wondering more about
consequences. It's probably a shot in the dark. It's only testing
right now so no big deal if something breaks.

Jan 28 '07 #5

P: n/a

You would probably be ok. I'd be a bit reluctant to do this, myself, though.

The problems might be if MS ever makes a change to the schema or stored
procs that would blow up any of your mods. Also, you need to remember to
make the changes in the membership schema anytime you switch the datastore
that holds your userids (say when you migrate from dev to QA, and then to
prodution, or if you ever had to rebuild your production ASPNETDB).

You might check to see about using personalization properites via the web
config. I think you can use this to create custom name/value pairs that are
stored in ASPNETDB.aspnet_Profile. See this
http://www.ondotnet.com/pub/a/dotnet...on.html?page=1

Jason Vermillion
"perplexed" wrote:
>

On Jan 27, 6:22 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
Add a column to the database and display that.

Juan, that's right but I guess I was wondering more about
consequences. It's probably a shot in the dark. It's only testing
right now so no big deal if something breaks.

Jan 28 '07 #6

P: n/a
There are a number of stored procedures for fetching data about users. For
example, try:

sqldsrc.SelectCommand = "SELECT Email FROM " & _
"vw_aspnet_MembershipUsers WHERE (UserName = 'kencox')"

Is that what you meant?

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>

"perplexed" <jo***@bigstring.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
After a user logs in (ASP.NET 2.0 membership/roles), how do I
programmatically access their UserId and other information stored in
the ASP.NET database structure? A user may login at Login.aspx and
then they are redirected to somepage.aspx. somepage.aspx doesn't have
a reference to the login object and can't access UserId.

Also, are there any issues with changing the UserId column from a
uniqueidentifier to an integer IDENT?

Thanks.

Jan 28 '07 #7

P: n/a


On Jan 27, 11:08 pm, "Ken Cox [Microsoft MVP]"
<BANSPAMkj...@newsgroups.nospamwrote:
There are a number of stored procedures for fetching data about users. For
example, try:

sqldsrc.SelectCommand = "SELECT Email FROM " & _
"vw_aspnet_MembershipUsers WHERE (UserName = 'kencox')"

Is that what you meant?
I meant existing structures rather than coding it all by hand. I few
sprocs will do it though.

Jan 28 '07 #8

P: n/a
re:
Juan, that's right but I guess I was wondering more about consequences.
None, whatsoever.

The caveat you got earlier was about changing the schema for existing fields,
not towards adding more fields. That's perfectly doable without consequences.

In fact, you can replace the whole database *and* membership provider with custom ones.

See :
http://www.devx.com/asp/Article/29256
and
http://weblogs.asp.net/scottgu/archi...esources-.aspx
The complete source code to the Membership provider, and all providers, is at:
http://weblogs.asp.net/scottgu/archi...-Download.aspx

Modify it to taste...

Finally, everything you could possibly want to know
about Providers is found in Jeff Prosise's MSDN article :

http://msdn2.microsoft.com/en-us/asp.net/aa336558.aspx


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"perplexed" <jo***@bigstring.comwrote in message
news:11*********************@j27g2000cwj.googlegro ups.com...
>

On Jan 27, 6:22 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
>Add a column to the database and display that.

Juan, that's right but I guess I was wondering more about
consequences. It's probably a shot in the dark. It's only testing
right now so no big deal if something breaks.

Jan 28 '07 #9

P: n/a
Is there a simple way to access the new column or will it just come
through in the Membership object?

Jan 28 '07 #10

P: n/a
re:
Is there a simple way to access the new column
That depends on what you call simple.

re:
will it just come through in the Membership object?
You'll have to modify the membership provider class.

Get the details for that class here:
http://msdn2.microsoft.com/en-us/library/aa478949.aspx


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"perplexed" <jo***@bigstring.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
Is there a simple way to access the new column or will it just come
through in the Membership object?

Jan 28 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.