新聞中心
偶然在CodeProject中發(fā)現(xiàn)土耳其人mascix已經(jīng)重寫了一套使用SQLite進(jìn)行用戶管理的Membership Provider,原文地址:http://www.codeproject.com/KB/aspnet/SQLiteProviders.aspx

創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)服務(wù)商,為中小企業(yè)提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)服務(wù),網(wǎng)站設(shè)計(jì),綿陽(yáng)服務(wù)器托管等一站式綜合服務(wù)型公司,專業(yè)打造企業(yè)形象網(wǎng)站,讓您在眾多競(jìng)爭(zhēng)對(duì)手中脫穎而出創(chuàng)新互聯(lián)公司。
如果對(duì)SQLite本地?cái)?shù)據(jù)庫(kù)開發(fā)和數(shù)據(jù)庫(kù)進(jìn)行開發(fā)的過(guò)程不太了解可以參考我上一篇文章《SQLite開發(fā)準(zhǔn)備》。
我們將mascix的代碼下載到本地打開,目錄中所見的ProviderSql.sql是Membership相關(guān)表的建表SQL文,我們使用SQLite Manager新建TestDatabas.sqlite數(shù)據(jù)庫(kù)。當(dāng)然我們也可以使用mascix在他的文章中推薦的SQLite Administrator來(lái)進(jìn)行數(shù)據(jù)庫(kù)的創(chuàng)建。
SQL文運(yùn)行完,數(shù)據(jù)庫(kù)中就會(huì)創(chuàng)建出如下六張數(shù)據(jù)表:
- Roles
- UsersInRoles
- aspnet_applications
- aspnet_profile
- personalization
- users
而mascix所寫的代碼的精華都在App_Code文件夾下的代碼里,為了以后復(fù)用這套代碼,我決定創(chuàng)建一個(gè)單獨(dú)的C#工程命名為SQLiteProviders。
并將App_Code代碼中的名稱空間都修改為SQLiteProviders(這里刪除了mascix.前綴,并不是忽視版權(quán)而是為了遵守代碼規(guī)范)。
新建的工程需要引用:
- System.Web
- System.Data.SQLite.DLL
- System.Web.ApplicationServices
- System.Security
編譯后創(chuàng)建一個(gè)新的Web工程,修改web.config代碼如下:
- connectionString="Data Source=|DataDirectory|users.sqlite;Version=3;" />
- defaultProvider="SQLiteRoleProvider"
- enabled="true"
- cacheRolesInCookie="true"
- cookieName=".ASPROLES"
- cookieTimeout="30" cookiePath="/"
- cookieRequireSSL="false"
- cookieSlidingExpiration="true"
- cookieProtection="All">
- name="SQLiteRoleProvider"
- type="SQLiteProviders.SQLiteRoleProvider"
- connectionStringName="ConnString"
- applicationName="CoolSpirit"
- writeExceptionsToEventLog="true"/>
- userIsOnlineTimeWindow="15">
- name="SQLiteMembershipProvider"
- type="SQLiteProviders.SqliteMembershipProvider"
- connectionStringName="ConnString"
- applicationName="CoolSpirit"
- enablePasswordRetrieval="false"
- enablePasswordReset="true"
- requiresQuestionAndAnswer="false"
- requiresUniqueEmail="true"
- passwordFormat="Hashed"
- writeExceptionsToEventLog="true"/>
- name="SQLiteProfileProvider"
- type="SQLiteProviders.SQLiteProfileProvider"
- connectionStringName="ConnString"
- applicationName="CoolSpirit"/>
- type="SQLiteProviders.SQLitePersonalizationProvider"
- connectionStringName="ConnString"
- applicationName="CoolSpirit"
- description="SQLite Personalization Provider"
- />
添加對(duì)SQLiteProviders項(xiàng)目的引用,別忘了以鏈接文件引用SQLite.Interop.DLL(見《SQLite開發(fā)準(zhǔn)備》一文)然后編譯Web應(yīng)用程序。
編譯通過(guò)后,在Visual Studio的菜單“項(xiàng)目”-“ASP.NET配置”,即可打開ASP.NET配置站點(diǎn),在安全鏈接的右側(cè),如果能看見“使您能夠設(shè)置和編輯用戶、角色和對(duì)站點(diǎn)的訪問(wèn)權(quán)限。 現(xiàn)有用戶: 0 ”的字樣即代表配置成功,隨后可以像ASP.NET Membership Provider一樣通過(guò)登陸控件等實(shí)現(xiàn)系統(tǒng)登陸、用戶注冊(cè)、用戶和角色管理等功能了。
名稱欄目:SQLite開發(fā)中的MermbershipProvider
當(dāng)前鏈接:http://m.fisionsoft.com.cn/article/cddpssh.html


咨詢
建站咨詢
