c# - How do I get SimpleMembershipProvider extended properties back from database like FirstName and LastName? -
following post, simplemembershipprovider, using multiple propertyvalues custom database tables, create new user using simplemembershipprovider , webmatrix.webdata.websecurity.
websecurity.createuserandaccount(model.username, model.password,new { firstname = model.firstname,lastname = model.lastname,appid = guid.newguid(), memberid = model.memberid});
however, have not been able find built-in methods retrieving information membershipprovider or websecurity methods. know query database directly information , update, code become tightly coupled test implementation.
anyone know how extended properties logged in user in simplemembershipprovider? thanks.
sbirthare right, however, since doesn't explain how this, allow me (this assuming use c# server-side language option, tagged, believe do. assumes table name in "firstname" , "lastname" columns belong is, in fact, "userprofile"):
since webmatrix comes sql server-ce, can use simple sql query this.
first set connection database:
var db = database.open("users");
next, compile appropriate string used query (a simple string variable used):
string selectquerystring = "select firstname, lastname userprofile";
the above string when passed query()
c# method (shown below), return list (specifically ienumerable<dynamic>
) of "firstname"s , "lastname"s returned database. if wanted rows returned can use where
clause in sql string, instead of above string make instead (this example, have tailor own conditions fit situation, should give easy example):
string selectquerystring = "select firstname, lastname userprofile email = @0 , userid = @1";
first let me address @0
, @1
is, in case don't know. placeholders end being filled conditions want test against (more on further down) using method, known "paramaterized queries", smoking gun against sql injection attacks. in short: use method conditions tested in clause (i can't stress enough).
now, i'm not sure how know sql querying, can powerful , useful , using things like
, order by
, group by
, join
, union
, and
, or
, or subqueries, as, many many other keywords , approaches, can make sql query return desire, in order desire (a great beginner sql query tutorial can found here: http://www.sqlcourse.com/index.html).
okay, moving on... once you've written selectquerystring way want to, need left store it, so:
int id = 6; string email = "testemailname@gmail.com"; var queryresultslist = db.query(selectquerystring, email, id); //here first argument passed `db.query()` method query string, each additional argument passed (and can pass array of values here instead if want) used fill `@0` , `@1` placeholders formed in string earlier (order ever important here!).
and display it, so:
foreach (var row in queryresultslist) { //do each row returned, here! <div>first name: @row.firstname</div><br/> <div>last name: @row.lastname</div> {
sorry if lot take in, thought @ least show of steps need make happen. there isn't it, felt giving bunch of helpful pointers long way :)
anyway, let me know if have questions or if need clarify anything.
edit:
well, saw use mvc opposed web-pages. answer web-pages environment, honest, i'm not sure if different or not because have never worked mvc. either way, sql query should same , since we're both using c#, idk.
either way, if told answer doesn't fit scenario or not useful you, glad delete it.
Comments
Post a Comment