在代碼中使用 WebSecurity 對象之前,必須創(chuàng)建或初始化 WebSecurity 數(shù)據(jù)庫。
在 web 更目錄中,創(chuàng)建或編輯 _AppStart.cshtml 頁面。
在該文件中寫入以下代碼:
@{ WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", true); }
網(wǎng)站每次啟動(dòng)時(shí)都會(huì)運(yùn)行以上代碼。它會(huì)對 WebSecurity 數(shù)據(jù)庫進(jìn)行初始化。
"Users" 是 WebSecurity 數(shù)據(jù)庫的名稱。(Users.sdf)
"UserProfile" 是包含用戶配置信息的數(shù)據(jù)庫表的名稱。
"UserId" 包含用戶 ID 的列的名稱(主鍵)。
"Email" 是包含用戶名稱的列名。
最后一個(gè)參數(shù) true 是一個(gè)邏輯值,指示應(yīng)創(chuàng)建用戶配置文件表和成員資格表(如果它們不存在),否則 false。
提示:盡管 true 指示自動(dòng)創(chuàng)建數(shù)據(jù)庫表,但數(shù)據(jù)庫本身不會(huì)被自動(dòng)創(chuàng)建。它必須存在。
2015職稱計(jì)算機(jī)考試書PowerPoint2007中 .. 定價(jià):¥45 優(yōu)惠價(jià):¥42 更多書籍 | |
2015年全國職稱計(jì)算機(jī)考試教材(2007模 .. 定價(jià):¥225 優(yōu)惠價(jià):¥213 更多書籍 |