2010-03-11 41 views
4

我有一個自定義的MembershipProvider和一個自定義RoleProvider。我通過創建實現MembershipProvider類的SimpleMembershipProvider類創建了自定義MembershipProvider。之後,我改變了我的web.config並工作。自定義RoleProvider與MVC 2.0 webconfig

所以我用同樣的方法創建自定義RoleProvider。沒什麼特別的,只是創建一個實現RoleProvider類的SimpleRoleProvider類。但後來當我改變web.config文件並運行該解決方案我收到以下錯誤信息:

的Web.Config

<membership defaultProvider="DashboardMembershipProvider"> 
<providers> 
    <clear/> 
    <add name="SimpleMembershipProvider" 
     type="Dashboard.Web.Controlling.Account.SimpleMembershipProvider" /> 
    </providers> 
</membership> 

<roleManager enabled="true" defaultProvider="DashboardRoleProvider"> 
    <providers> 
     <clear/> 
     <add name="DashboardRoleProvider" 
      type="Dashboard.Web.Controlling.Account.DashboardRoleProvider" /> 
    </providers> 
</roleManager> 


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. 

Parser Error Message: No parameterless constructor defined for this object. 

Source Error 
Line 78:   <add name="SimpleRoleProvider" 
Line 79:   type="Dashboard.Web.Controlling.Account.SimpleRoleProvider" /> 

於是我在網上搜索。並試圖對類型屬性,它會生成以下錯誤:

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. 

Parser Error Message: Could not load file or assembly 'Dashboard.Web.Controlling.Account' or one of its dependencies. The system cannot find the file specified. 

Source Error: 
Line 78:   <add name="SimpleRoleProvider" 
Line 79:    type="Dashboard.Web.Controlling.Account.SimpleRoleProvider,Dashboard.Web.Controlling.Account" /> 

我如何將能夠得到這個CustomRoleProvider工作有什麼建議? 任何幫助,非常感謝!

回答

3

從您得到DashboardRoleProvider需要具有無參數構造函數的第一個異常開始。否則,框架無法實例化角色提供者。

在第二個示例中,您可能想改爲使用完全限定的程序集名稱。

Michael

2
<add name="SimpleRoleProvider"   type="Dashboard.Web.Controlling.Account.SimpleRoleProvider,Dashboard.Web.Controlling.Account" /> 

第一個逗號後面的類型部分是程序集名稱,您確定您的程序集名稱不僅僅是Dashboard.Web嗎?

右鍵單擊項目並選擇屬性,它將找到您的程序集名稱。

相關問題