Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 25th, 2011, 12:59 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2011
Posts: 32
Thanks: 22
Thanked 0 Times in 0 Posts
Default Capture value in aspnet_USERS

I am using login controls from ch. 16 and once I have created an account for a user, the username "value" appears as it should in the ASPNETDB.MDF database in the aspnet_USERS table in the UserName field.

I would like to be able to "capture" that UserName field value and then store that same value in another database table.

I can capture the field value in the UserName in Login.aspx with UserName.Text and assign it to Profile.UserName, but the user has not been validated at that point so am thinking that obtaining value from aspnet_Users would be better and making assignment in DestinationPageURL page.

Would appreciate any code thoughts

Thank you

Last edited by esherr01; September 25th, 2011 at 01:25 PM.. Reason: More clear question
Reply With Quote
  #2 (permalink)  
Old September 25th, 2011, 01:43 PM
Friend of Wrox
Points: 547, Level: 8
Points: 547, Level: 8 Points: 547, Level: 8 Points: 547, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 125
Thanks: 20
Thanked 3 Times in 3 Posts
Default

hi esherr11,
I don't understand exactly what is your question but You can access username of user, who is authenticated, by User.Identity.Name .
Do i understand your question?
__________________
Please excuse me for poor and bad English.
Reply With Quote
  #3 (permalink)  
Old September 25th, 2011, 01:59 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2011
Posts: 32
Thanks: 22
Thanked 0 Times in 0 Posts
Default ...more

If I can access the authenticated UserName from the aspnet_USERS table in ASPNETDB.MDF, I want to add that value to one of my own tables in another database. My table has just two fields, Customer_ID and UserName. The Customer_ID is my Identity (primary key)field for the table, thus by adding the accessed UserName to that table, I will get an integer value placed in Customer_ID and that is the value I need and will need to use in other pages.

Hope this helps

My current code in Default.aspx.cs is:

Code:
protected void Page_Load(object sender, EventArgs e)
    {
       string NameINeed;
       NameINeed = Profile.UserName;

       if (!Page.IsPostBack) 
       {
          
          GolfDatabaseDataContext db = new GolfDatabaseDataContext();

          //Here we check to see if UserName already exists
          //If not, then add to table Customer

          if (!db.Customers.Any(u => u.UserName == NameINeed)) 
          {
             Customer cust = new Customer();

             cust.UserName = NameINeed;

             db.Customers.InsertOnSubmit(cust);
             db.SubmitChanges();
          }//end inner if

       }//end outer if

    }//end method
Problem is that Profile.UserName is not "doing the job" for me in accessing the authenticated UserName of the logged in user.

Thank You
Reply With Quote
  #4 (permalink)  
Old September 25th, 2011, 02:07 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2011
Posts: 32
Thanks: 22
Thanked 0 Times in 0 Posts
Default ........more

...maybe I don't need to access ASPNETDB.MDF.

I just need the authenticated UserName value that was entered in my login.aspx that is pretty exact to Ch. 16 with a Username filed and Password field in the login control.
Reply With Quote
  #5 (permalink)  
Old September 25th, 2011, 02:09 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

As Morteza suggested, you can use User.Identity.Name to retrieve the currently logged in user's name.

Cheers,

Mar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
esherr01 (September 25th, 2011)
  #6 (permalink)  
Old September 25th, 2011, 02:11 PM
Friend of Wrox
Points: 547, Level: 8
Points: 547, Level: 8 Points: 547, Level: 8 Points: 547, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 125
Thanks: 20
Thanked 3 Times in 3 Posts
Default

I think you should do following steps:
1- Make your customer_ID field auto increment(Do you know how?)
2- Copy your own table( only structure of table) to aspnetdb.mdf (Do you know how?) .
3- Select only username field of aspnet_USERS from aspnetdb.mdf and insert this temporary table into your own table (Do you know how?).
4- Publish this table for provider and execute sql code in your own database (Do you know how?).
I hope it help you.
Any doubt, Please comment.
__________________
Please excuse me for poor and bad English.
Reply With Quote
The Following User Says Thank You to morteza For This Useful Post:
esherr01 (September 25th, 2011)
  #7 (permalink)  
Old September 25th, 2011, 02:13 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2011
Posts: 32
Thanks: 22
Thanked 0 Times in 0 Posts
Default .....more

so what would you think of:

string NameINeed;

if(User.Identity.IsAuthenticated)
{
NameINeed = User.Identity.Name.ToString();
}
Reply With Quote
  #8 (permalink)  
Old September 25th, 2011, 02:17 PM
Friend of Wrox
Points: 547, Level: 8
Points: 547, Level: 8 Points: 547, Level: 8 Points: 547, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 125
Thanks: 20
Thanked 3 Times in 3 Posts
Default

I think this is correct.
If it not worked , Please comment.
__________________
Please excuse me for poor and bad English.
Reply With Quote
The Following User Says Thank You to morteza For This Useful Post:
esherr01 (September 25th, 2011)
  #9 (permalink)  
Old September 25th, 2011, 04:57 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Code:
NameINeed = User.Identity.Name.ToString();
The Name property is already a string, so you can drop the last call to ToString():

Code:
NameINeed = User.Identity.Name;
Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 - Page 807 Set Capture and Get Capture bratkichawy BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 0 September 24th, 2011 11:27 AM
capture URL SKhna ASP.NET 2.0 Basics 1 February 5th, 2008 11:02 AM
Return UserId from aspnet_Users rao965 ASP.NET 2.0 Professional 4 July 12th, 2007 04:50 PM
Which event(s) should be used to capture changes lxu Access 2 April 14th, 2004 09:14 AM



All times are GMT -4. The time now is 05:18 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.