简体   繁体   English

mvc中的简单会员提供者

[英]simple membership provider in mvc

How to make simple Membership provider from empty web application template in ASP.NET MVC4 如何从ASP.NET MVC4中的空Web应用程序模板创建简单的成员资格提供程序

I searched a lot on google, bing and many others, but I din't get positive responce about membership provider 我在google,bing和许多其他人上搜索了很多,但我对会员提供商没有得到积极的回应

can some one tell me basic of membership provider? 有人可以告诉我会员提供者的基本情况吗?

please

I followed these steps: 我按照以下步骤操作:

So before starting I am assuming you have setup your database models including a users model which we will use for simple membership. 所以在开始之前我假设您已经设置了数据库模型,包括我们将用于简单成员资格的用户模型。 Go ahead and add a "username" column and an "id" column (if you don't already have one) in the model and create the database. 继续在模型中添加“用户名”列和“id”列(如果您还没有),并创建数据库。 Remember already having a database is necessary if you want to use simple membership with your existing user's table. 请记住,如果要在现有用户的表中使用简单成员资格,则必须拥有数据库。 Simple membership will add it's table to your existing database. 简单的成员资格会将其表格添加到现有数据库中。

1.Install Webmatrix.webdata and webmatrix.data from Nuget Packet manager. 1.从Nuget Packet manager安装Webmatrix.webdata和webmatrix.data。

2.In your web.config enable simple membership by 2.在您的web.config中启用简单成员资格

<add key="enableSimpleMembership" value="true" />

in appsettings 在appsettings

3.Next step is to define profile, role and membership providers in system.web by 3.接下来的步骤是在system.web中定义配置文件,角色和成员资格提供程序

<profile defaultProvider="SimpleProfileProvider">
      <providers>
        <add name="SimpleProfileProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" connectionStringName="YOUR_CONNECTION_STRING" applicationName="/" />
      </providers>
    </profile>
    <membership defaultProvider="SimpleMembershipProvider">
      <providers>
        <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
      </providers>
    </membership>
    <roleManager enabled="true">
      <providers>
        <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
      </providers>
    </roleManager>

4.Next step is to connect your user table with simple membership. 4.接下来的步骤是将您的用户表与简单的成员资格连接起来。 Now the Internet Application Template which is being provided by default uses a filter but we're going to skip it. 现在默认提供的Internet应用程序模板使用过滤器,但我们将跳过它。 We're going to directly initialize simple membership in global.asax by 我们将直接初始化global.asax中的简单成员资格

if (!WebSecurity.Initialized)
            {
                WebSecurity.InitializeDatabaseConnection("YOUR_DB_CONTEXT", "USER_TABLE", "ID_COLUMN", "USERNAME_COLUMN", true);
            }

And you are done with the setup. 你完成了设置。

Now to actually create users, there are two options, Create User and Account and Create Account only. 现在要实际创建用户,有两个选项,创建用户和帐户以及仅创建帐户。 How the create user and account works is that it will you will provide the user's information and it will create a user in your user table and then create a membership account. 创建用户和帐户的工作原理是,您将提供用户的信息,并在用户表中创建用户,然后创建会员帐户。 I personally use the latter, which means I create the users separately, and then create a membership account for that user using 我个人使用后者,这意味着我单独创建用户,然后使用创建该用户的会员帐户

WebSecurity.CreateAccount("Username","Password");

Just create an Internet template, and copy the code out of it into your empty project.. although, honestly at that point you've essentially got the Internet template anyways, other than the default layout. 只需创建一个Internet模板,并将其中的代码复制到您的空项目中。但是,老实说,此时您基本上已经获得了Internet模板,而不是默认布局。

There's a lot of code that goes into supporting the Membership system, so study the Internet template and it will tell you everything you need to know. 有很多代码支持会员系统,所以研究互联网模板,它会告诉你需要知道的一切。

When you create the new project, select the Internet Template. 创建新项目时,请选择“Internet模板”。 When you register your first user it will automatically create the table structure in your db 注册第一个用户时,它将自动在数据库中创建表结构

So you want to use simple membership in asp.net MVC4 . 所以你想在asp.net MVC4中使用简单的成员资格。
Follow the steps mentioned in this tutorial : Simple Membership 按照本教程中提到的步骤操作: 简单成员身份

This will provide the all the basic information of how to setup simple membership in asp.net mvc4. 这将提供有关如何在asp.net mvc4中设置简单成员资格的所有基本信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM