You can do something like this fairly easily:
Membership.GetAllUsers().Cast<MembershipUser>()
.Where(u => true /*insert your criteria here*/)
.ToList().ForEach(user =>
{
var p = ProfileBase.Create(user.UserName, true);
// do whatever you want to the profile here
int counter = (int)p["Counter"];
counter++;
p["Counter"] = counter;
p.Save();
});
The above code will work as-is in any handler of your site, but if you want to do it with a console app, simply copy the <system.web>
section from your web.config
to the app.config
of the console app.
caveat: if you are using the default provider connection string, localSqlServer
, you will need to create a new connection string explicitly pointing to the .mdf as only web applications have a concept of DATADIRECTORY
(app_data).