MVC4 : What entity represents table webpages_Membership
Asked Answered
B

1

6

I'm trying to access webpages_Membership table (I'm using SimpleMembership) to retrieve the account ConfirmationToken.

How do I access this table from my model/controller/DAL?

The only thing I can think of is executing pure SQL from my code to get this value, but that's doesn't seem like it's the right thing to do, nor elegant.

Bluefarb answered 23/9, 2012 at 5:22 Comment(0)
T
2

From what I understand, there's no direct way to retrieve the value using WebSecurity helper.

When you create a User and Account the method returns the confirmation token:

string confirmationToken = WebSecurity.CreateUserAndAccount("tester", "test123", requireConfirmationToken: true);

You then send this token (inside a link as a QueryString parameter for example) to the User's e-mail address. When the user clicks the link, your app must get/read this token and then you must call:

WebSecurity.ConfirmAccount(userName, confirmationToken);

As you mentioned you can of course hit the db directly writing your own SQL or even add the webpages_Membership to an EntityFramewok EDMX model and query the table directly:

var confirmationToken = Database.Memberships.Single(m => m.UserId == userId).ConfirmationToken;

More on this:

Using the confirmation feature for ASP.NET Web Pages security

Get Account Confirmation Token?

Triplet answered 4/10, 2012 at 22:11 Comment(2)
Thanks Leniel. What you described is my intention, but sometimes the user (for whatever reason) wants to have the confirmation email re-sent. How would we implement a re-send function without using custom sql to retrieve the original confirmationToken?Bluefarb
In this case you can use the Database helper described here to retrieve the confirmationToken for the user: mikesdotnetting.com/Article/156/…Triplet

© 2022 - 2024 — McMap. All rights reserved.