472,799 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

Accessing membership UserId programmatically?

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
10 4782

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


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

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


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
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
Is there a simple way to access the new column or will it just come
through in the Membership object?

Jan 28 '07 #10
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: hikkk | last post by:
I have an application named "wr",and the local destination is "wwwroot\wr",my default website is "wwwroot". when i create an new user "kkk",i found that,in table aspnet_Application,the...
6
by: matt | last post by:
hello, im working on my first public-facing ASP.NET 2 website, and i have a question/concern about authentication integration. in ASP.NET 1.1, one would typically go w/ a "role yer own"...
1
by: ibiza | last post by:
Hi, what would be the simplest way to add a functionality so it is possible to change the username in an asp.net 2.0 webapplication that uses SqlMembershipProvider? By default, this providers...
1
by: Amir Ghezelbash | last post by:
Hello all, I need help with sql server which i was wondering if someone can shed some light on my problem The problem: Hello all, I need help with sql server which i was wondering if someone...
3
by: Dabbler | last post by:
I need to have users login using the ASP.NET sqlprovider but then would like to direct them to a page based on some info in a separate table. Is there code to generate the strange userid field in...
1
by: =?Utf-8?B?aGZkZXY=?= | last post by:
Hello, I have a web application that makes use of the SQL Membership and Role providers. My app has admin screens to manage users (membership), roles, and supplementary user data. I have just...
5
by: Jonathan Wood | last post by:
Greetings, I'm using ASP.NET membership and I'd like to query the number of users in a particular role. I don't want the overhead of returning a dataset and then getting the number of items...
7
by: Jonathan Wood | last post by:
Is there any way to specify a user's name using ASP.NET membership? I know there is a UserName property but that's a unique login name, and not ideal for the user's actual name. (Also, I'm going...
5
by: DotNetNewbie | last post by:
Hi, I am developing an application that has to scale and be very efficient, and I am using asp.net membership in my application. I set things up in my Users table (it has extra columns that I...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.