0

我正在寫簡單成員和角色提供程序。 我試圖從運行後的代碼http://www.brianlegg.com/post/2011/05/09/Implementing-your-own-RoleProvider-and-MembershipProvider-in-MVC-3.aspx但運行IIS告訴我錯誤:MVC3/MVC4中的簡單成員和角色提供程序

Configuration Error 
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Line 39:  <providers> 
Line 40:   <clear /> 
Line 41:   <add name="LocalBankMembershipProvider" type="LocalBank.Helpers.LocalBankMembershipProvider, LocalBank" connectionStringName="LocalBankEntities" /> 
Line 42:  </providers> 
Line 43:  </membership> 

Message Parser Error: Target call threw an exception. 
Line: 41 

當我在項目開始時犯了一個錯誤? 將使用Nuget包從mvc3轉換爲mvc4的項目

我該如何解決這個錯誤?

回答

0

您是否按照相同鏈接的評論部分給出了建議?

幾件事情要嘗試:

  1. 這可能是連接字符串是錯誤的,因爲你看到了這個錯誤。更改連接字符串(例如數據源)。如果您仍然看到問題,請調試該項目並查看它究竟粘在哪裏以及您可以獲得哪些更多信息。我能夠重現這個問題,並解決了連接字符串的變化。

  2. 當您調試時,您會發現它會在檢查角色存在時引發異常。按照博客上,你需要添加默認角色「經理人」:

The only thing to note is there are no roles created. If you look inside the AccountController Register HttpPost action you'll notice that any user who registers through this site is given a default role of "Member". This can be changed, but whatever role this is must first already be created in the Role table. You can do this by writing a script (most likely preferred method) or you can write some hacky code and call it real quick since it will only need to be ran 1 time when first creating roles. Here's some example code you can use to create the "Member" role, modify it to suit your needs.

LocalBankRepository repo = new LocalBankRepository(); 
repo.AddRole("Member"); 
repo.Save(); 

Call those 3 lines from somewhere in your code (or a separate "initializer" project) and from then on the code should work as expected. Sorry for the confusion.

如果你仍然面臨的問題與共享更多的細節。希望這可以幫助。

相關問題