在简单的MVC成员资格提供 [英] simple membership provider in mvc

查看:82
本文介绍了在简单的MVC成员资格提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使从空的Web应用程序模板简单成员提供商ASP.NET MVC4

How to make simple Membership provider from empty web application template in ASP.NET MVC4

我搜索谷歌,必应和其他许多人很多,但我din't得到有关成员提供积极的反响。

I searched a lot on google, bing and many others, but I din't get positive responce about membership provider

可以有一个人告诉我基本成员提供的?

can some one tell me basic of membership provider?

推荐答案

我按照下列步骤操作:

所以,在开始之前我假设你已经设置你的数据库模型,包括我们将使用简单的会员资格的用户模式。来吧,添加一个用户名栏和ID列(如果你不已经有一个)模型和创建数据库。记得已经有一个数据库,如果你想用简单的会员与您现有的用户的表是必要的。简单的会员将增加它的表,以现有的数据库。

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. 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.安装Webmatrix.webdata和包的NuGet经理webmatrix.data。

1.Install Webmatrix.webdata and webmatrix.data from Nuget Packet manager.

2.In你的web.config实现简单籍由

2.In your web.config enable simple membership by

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

在AppSettings的

in appsettings

3.Next步骤是定义在System.Web程序配置文件,作用和成员由供应商

3.Next step is to define profile, role and membership providers in system.web by

<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一步是将用户表简单的会员连接。现在正在由默认提供的互联网应用程序模板使用过滤器,但我们要跳过它。我们将通过

4.Next step is to connect your user table with simple membership. Now the Internet Application Template which is being provided by default uses a filter but we're going to skip it. We're going to directly initialize simple membership in global.asax by

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

和您使用安装完成。

现在实际创建的用户,有两种选择,创建用户和帐户,只有创建帐户。如何创建用户帐户和作品是它将你将提供用户信息,它会在用户表中创建一个用户,然后创建一个会员帐户。我个人使用后者,这意味着我分别创建用户,然后创建一个使用该用户的会员帐户

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");

这篇关于在简单的MVC成员资格提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆