Avatar of bidgadget
bidgadget
Flag for United States of America asked on

ASP.NET 4 Visual Studio 2010. Membership Website Question

I have a asp.net 4 membership web with roles.  When a user goes to change his password, I want to display that particular users Password Questiion.  I added a dataset form view to the membership database and am able to achieve this by a sql query when I specify the users actual name in the query.  I want to change my code to query the databased based on the user that is logged in.

Basically I want to change the part in my code that says
WHERE (aspnet_Users.UserName = 'RICK')
 to  something like

Where aspnet_users.username = (the currently logged in user)

I am not sure what to replace "the logged in user" with to make it equal the currently logged in user

any help would be appreciated.
SELECT aspnet_Membership.PasswordQuestion, aspnet_Membership.PasswordAnswer FROM aspnet_Membership INNER JOIN aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId WHERE (aspnet_Users.UserName = 'RICK')

Open in new window

Web DevelopmentASP.NETMicrosoft SQL Server

Avatar of undefined
Last Comment
bidgadget

8/22/2022 - Mon
Carl Tawn

The following should give you that:
Membership.GetUser().Username

Open in new window

bidgadget

ASKER
Thank you for your response.  But how would I add that to my sql query?
Carl Tawn

Are you using inline SQL or calling a stored procedure? If it is inline you would do something like (assuming C#):
string username = Membership.GetUser().UserName;
string sql = string.Format("SELECT aspnet_Membership.PasswordQuestion, aspnet_Membership.PasswordAnswer FROM aspnet_Membership INNER JOIN aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId WHERE (aspnet_Users.UserName = '{0}')
", username);

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
bidgadget

ASKER
I am using inline sql and with VB
Carl Tawn

In that case:
Dim username As String = Membership.GetUser().UserName
Dim sql As String = String.Format("SELECT aspnet_Membership.PasswordQuestion, aspnet_Membership.PasswordAnswer FROM aspnet_Membership INNER JOIN aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId WHERE (aspnet_Users.UserName = '{0}')
", username)

Open in new window

bidgadget

ASKER
Ok, I will give it a try.  Do I just paste the code into in the "define custum sql or stored procedure"?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Carl Tawn

Depends how you are trying to get at the data.
bidgadget

ASKER
I added a list view, then made a connection string to the membership database.  Then I am at the part where I am creating the custom sql query to return the question.  Thank you so much
bidgadget

ASKER
I am not sure if I add the sql statement in the vb or sql part
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Carl Tawn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
bidgadget

ASKER
OK.  When I put the first code in, it takes me to another screen that says it recognizes I have a parameter "username"  It is asking me for a parameter source, a query string fiels and a default value
Carl Tawn

Ah, it's a little smarter than I gave it credit for :)   Leave the source set to "None" and the default value empty, unless you want to give it a default.
bidgadget

ASKER
Still having a little trouble, page coming up blank, but i will play around with it.  Most likely I am not implementng correctly.  Thaks again for all your help
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
bidgadget

ASKER
thanks again