簡體   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