2012-12-13 21 views
0

我已經調用了_appstart.cshtml中的WebSecurity.InitializeDatabase,如各種谷歌搜索中所述,但定期在繼續調用WebSecurity.IsAuthenticated時收到以下錯誤,例如,我會假設初始化數據庫每次進入網站的用戶都會調用一次,在調用_pagestart.cshtml之前是否存在這種初始化的延遲?WebMatrix WebData InitializeDatabaseConnection

You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site. 

at WebMatrix.WebData.SimpleMembershipProvider.VerifyInitialized() 
at WebMatrix.WebData.WebSecurity.VerifyProvider() 
at WebMatrix.WebData.WebSecurity.Logout() 
at ASP._Page__PageStart_cshtml.Execute() 

回答

0

不,不應該有延遲。

要使用WebSecurity.InitializeDatabaseConnection,您只需調用參數autoCreateTables = true即可。在數據庫中設置表後,然後從_appstart開始,將使用autoCreateTables = False調用WebSecurity.InitializeDatabaseConnection。