我在使用EF的ASP.NET自定義成員資格實現方面遇到問題。事情是,我的web.config具有提供程序的默認值,但在運行時,這些默認值僅在Initialize()中讀取,第一次提供程序實例化(例如,當我通過GET請求Register視圖時發生,但當我填寫表格和POST對供應商類控制器初始化()不會被調用,所有的供應商設置是空的或默認值類型值未從web.config讀取成員資格提供程序屬性
這是我的web.config部分:
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider"
type="BN.Membership.EfMembershipProvider, BN"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider"
type="BN.Membership.EfRoleProvider, BN"
connectionStringName="ApplicationServices"
applicationName="/" />
</providers>
</roleManager>
因爲我的供應商類是相當巨大的,我不是在這裏張貼,但如果要求將發佈它的某些部分。
這是否有幫助:http://stackoverflow.com/questions/623545/how-do-i-call-initialize-on-a-custom-membershipprovider - 發佈初始化提供商在該帖子中的代碼將有所幫助。 – jfar 2010-10-22 17:02:38
謝謝,您的評論幫助我意識到我需要從Membership.Providers集合中獲取實例,但這需要無參數的構造函數。我忘了提及我使用Ninject,因此顯然遇到了這個問題http://stackoverflow.com/questions/2753424/dependency-injection-with-custom-membership-provider – mare 2010-10-22 18:27:34
看來我不得不使用這個http://commonservicelocator.codeplex.com/ ..你在你的項目中使用它嗎? – mare 2010-10-22 18:48:07