繁体   English   中英

如何从asp.net MVC 4中的空Web应用程序模板制作简单的成员资格提供程序?

[英]how to make simple membership provider from empty web application template in asp.net mvc 4?

如何从空的ASP.NET MVC 4模板开始配置简单成员资格提供程序?

我在Google,必应(Bing)和许多其他网站上进行了很多搜索,但未获得有关会员资格提供者的正面评价。

有人可以告诉我简单会员资格提供者的基本知识吗?

我刚刚完成了整个过程,步骤如下。 我假设您将使用Entity Framework进行数据访问,并且已经进行了设置:

  • 参考库WebMatrix.DataWebMatrix.WebData 您可以在“添加引用”对话框的“装配件/扩展名”下找到它们。
  • 将以下部分添加到Web.config
<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=LicenceAudit.mdf;Integrated Security=SSPI;attachDBFilename=|DataDirectory|\LicenceAudit.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
<system.web>
<membership defaultProvider="simpleMembershipProvider">
      <providers>
        <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="SimpleRoleProvider">
  <providers>
    <clear/>
    <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
  </providers>
</roleManager>
</system.web>
  • WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UsersTableName", "UserId", "UserName", true)Global.asax.cs Application_Start()
  • 确保您的数据库文件存在并包含适当的表。 UserId属性应为int类型。
  • 通过执行WebSecurity.CreateUserAndAccount("testUser", "myStrongPassword")测试所有内容。 如果通过,则无任何问题。

这是一篇简短的文章,逐步介绍了如何将ASP.NET SimpleMembership添加到现有的MVC 4应用程序:

http://www.mono-software.com/blog/post/Mono/226/Adding-ASP-NET-SimpleMembership-to-an-existing-MVC-4-application/

暂无
暂无

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

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