0
我們在我們的應用程序中使用asp.net配置文件提供程序,我需要爲大多數用戶更新一個特定的屬性。有沒有人編寫過控制檯應用程序或示例代碼?我們不以字符串格式存儲屬性。此二進制流位於aspnet_Profile表中。需要一個快速的方法來大規模更新所有用戶的PropertyValuesBinary字段
感謝, 馬力
我們在我們的應用程序中使用asp.net配置文件提供程序,我需要爲大多數用戶更新一個特定的屬性。有沒有人編寫過控制檯應用程序或示例代碼?我們不以字符串格式存儲屬性。此二進制流位於aspnet_Profile表中。需要一個快速的方法來大規模更新所有用戶的PropertyValuesBinary字段
感謝, 馬力
你可以做這樣的事情很容易:
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)的概念。