PC Review


Reply
Thread Tools Rate Thread

Accessing membership UserId programmatically?

 
 
perplexed
Guest
Posts: n/a
 
      27th Jan 2007
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.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFzb24gVmVybWlsbGlvbg==?=
Guest
Posts: n/a
 
      28th Jan 2007

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.
>
>

 
Reply With Quote
 
perplexed
Guest
Posts: n/a
 
      28th Jan 2007
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?

 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      28th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>



 
Reply With Quote
 
perplexed
Guest
Posts: n/a
 
      28th Jan 2007


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.

 
Reply With Quote
 
=?Utf-8?B?SmFzb24gVmVybWlsbGlvbg==?=
Guest
Posts: n/a
 
      28th Jan 2007

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.
>
>

 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      28th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
perplexed
Guest
Posts: n/a
 
      28th Jan 2007


On Jan 27, 11:08 pm, "Ken Cox [Microsoft MVP]"
<BANSPAMkj...@newsgroups.nospam> wrote:
> 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.

 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      28th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
> 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.
>



 
Reply With Quote
 
perplexed
Guest
Posts: n/a
 
      28th Jan 2007
Is there a simple way to access the new column or will it just come
through in the Membership object?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Membership - Getting user information by UserId mazdotnet Microsoft Dot NET 0 12th Sep 2007 03:52 AM
ASP.NET MemberShip getting user info by UserId mazdotnet Microsoft ASP .NET 0 12th Sep 2007 03:50 AM
Why no UserID property in the Membership class? ILaughLouder@gmail.com Microsoft ASP .NET 3 16th Aug 2006 07:48 PM
getting the membership userid from username when anonymous? neilmcguigan@gmail.com Microsoft ASP .NET 0 28th May 2006 08:19 AM
Accessing the UserID or Name in Access 2000 Microsoft Newgroups Microsoft Access VBA Modules 1 12th Jul 2005 07:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:01 PM.