Create Custom Memebership Provider in MVC 4 Always get error

别来无恙 提交于 2019-12-11 10:08:40

问题


I tried to develop custom membership provider in order to use with my own database tables but I couldn't. After run project I saw red error line on web.config custom membership provider line. :( type="Mvc4ApplicationTest2.Models.CustomMembershipProvider" I found article that said me to add below lines to web.config and I did.

add key="enableSimpleMembership" value="false"
add key="autoFormsAuthentication" value="false" 

Now application run :) but after get to login page and clicked on submit i get to new error that hint me like this:

To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".

Again I searched and I found some articles says me have to add prior line to web.config but with true value !!? add key="enableSimpleMembership" value="true" I confused. ?( So What can I do? Can everyone please help me? and other question, I want to use the standard, strong and useful method to secure my web application. do you think if I must use websecurity classes or other approach?

Sincerely Ali


回答1:


Here is how I registered my custom membership provider in the Web.config file of my MVC 4 project:

<membership defaultProvider="MyCustomMembershipProvider">
    <providers>
        <clear />
        <add name="MyCustomMembershipProvider" type="MyProject.MyCustomMembershipProvider, MyProject" connectionStringName="MyConnectionString" />
    </providers>
</membership>

Note that "MyProject.MyCustomMembershipProvider" should be the fully qualified path to your membership class, and "MyProject" is the name of the assembly it is contained in (usually your project name).

Also be sure that your membership provider class extends the MembershipProvider, like so:

public class MyCustomMembershipProvider : MembershipProvider
{
    // Code here
}

I do not have the 'enableSimpleMembership' or 'autoFormsAuthentication' lines in my Web.config.

Hopefully this helps!




回答2:


After searching a lot and reading many articles I found it Finally. That is stupid mistake. I used to inherit from System.Web.Security.MembershipProvider. so I took error about needing ExtendedMembershipProvider implementation. So I did it with WebMatrix.WebData.ExtendedMembershipProvider and then every things were fine. Thanks for all advises and helps.



来源:https://stackoverflow.com/questions/13425163/create-custom-memebership-provider-in-mvc-4-always-get-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!