2010-04-28 29 views

回答

1

你可以做這樣的事情很容易:

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(); 
    }); 

上面的代碼將工作,是在你的網站的任何處理,但如果你想這樣做使用控制檯應用程序,只需將<system.web>部分從web.config複製到控制檯應用程序的app.config即可。注意:如果使用默認提供程序連接字符串localSqlServer,則需要創建明確指向.mdf的新連接字符串,因爲只有Web應用程序具有DATADIRECTORY(app_data)的概念。

相關問題