Tải bản đầy đủ - 0 (trang)
Chapter 12. Configuring a Membership Database

Chapter 12. Configuring a Membership Database

Tải bản đầy đủ - 0trang

Chapter12.ConfiguringaMembership

Database

INTHISCHAPTER

AnIntroductiontoASP.NETMembership174

UsingtheDefaultMembershipDatabase175

UsingSQLServer2000orSQLServer2005forMembership

176

Checkpoint184



AnIntroductiontoASP.NETMembership

OneofthemostcommonquestionsIseefromwebdesigners

is,"HowdoIpasswordprotectmysiteorpartofmysite?"The

mostcommonmethodofpassword-protectingcontentistoset

permissionsonfilesandfolderssothatonlysomeonewhohas

beengivenpermissioncanaccessthem.Thattechniqueworks

great,butithassomeshortcomings.Whenusingthis

technique:

Managingusersandgroupsissometimesnotpossible

becauseitoftenmustbedoneonthewebserveritself.

Youdon'thavethecapabilityofallowinguserstocreate

theirownaccount.

Userscannotretrieveorresetalostpassword.

Designerscannotimplementaweb-basedloginsystem.

ASP.NETmembershipwasdesignedtoaddresstheseandother

shortcomings.ThemembershipfeaturesofASP.NETmakeit

easytoimplementapassword-protectedwebsite(orpartofa

site)thatiscompletelyweb-based.



TheMembershipProvider



ASP.NEThasmanybuilt-incapabilitiesthatdeveloperscantake

advantageofwithoutwritinganycode.Partofwhatmakesthat

possibleisacollectionofpre-builtcomponentscalledproviders

thatsupplyaspecifictypeoffunctionality.

ASP.NETmembershipusesabuilt-inmembershipproviderto

makeitsfeaturesavailabletoyou.Themembershipprovider

dictatesspecificsabouthowthemembershipsystemis

implemented.Forexample,someofthecapabilitiesprovidedby

thedefaultmembershipproviderare

AconnectiontoaSQLServer2005ExpressEdition

database.

Passwordstrengthandlengthrequirements.

Logincapabilityforthewebsiteortheprotectedpartofa

site.

Capabilitytocreateusersandforuserstocreatetheirown

accounts.

Abilityforuserstoretrievealostpasswordorresetit.

Accesstocontrolledcontentbasedonusersand/orgroups.

Someofthecapabilitiesofthedefaultmembershipprovidercan

bemodified.Forexample,youcanmodifythedatabase

connectionstringsothemembershipproviderusesaSQL

Server2005orSQLServer2000databasewithoutchanging

providers.However,somechangesrequirethatyoueither

modifythedefaultprovideroruseadifferentprovider.

SupposeyouwanttouseaMySQLdatabaseforyour

membershipsystem.Todothat,youneedtouseacustom

providertoprovidethatfunctionality.However,thatcustom

providerhastoprovideonlytheportionofthemembership

systemthatcommunicateswiththedatabase.Otherlogin

functionalitycanbeprovidedbyexistingASP.NETmembership

features.



Tip

Thecreationofcustommembershipprovidersisfar

beyondthescopeofthisbook.However,inmostcases,

ifyoudesirespecificfunctionality,youcanfindathirdpartyproviderthatyoucanuseatnocharge.

Forthepurposesofthisbook,youdon'treallyneedto

understandtheprovidermodelorhowitallworks,butit's

helpfulinseeingthebigpicturetoknowthatthefunctionalityof

yourmembershipsystemissuppliedbythemembership

provider.



PartIV:ASP.NETMembership









12ConfiguringaMembershipDatabase

13AddingandManagingUsersandRoles

14AddingandConfiguringLoginandUser

ManagementPages



Chapter12.ConfiguringaMembership

Database

INTHISCHAPTER

AnIntroductiontoASP.NETMembership174

UsingtheDefaultMembershipDatabase175

UsingSQLServer2000orSQLServer2005forMembership

176

Checkpoint184



AnIntroductiontoASP.NETMembership

OneofthemostcommonquestionsIseefromwebdesigners

is,"HowdoIpasswordprotectmysiteorpartofmysite?"The

mostcommonmethodofpassword-protectingcontentistoset

permissionsonfilesandfolderssothatonlysomeonewhohas

beengivenpermissioncanaccessthem.Thattechniqueworks

great,butithassomeshortcomings.Whenusingthis

technique:

Managingusersandgroupsissometimesnotpossible

becauseitoftenmustbedoneonthewebserveritself.

Youdon'thavethecapabilityofallowinguserstocreate

theirownaccount.

Userscannotretrieveorresetalostpassword.

Designerscannotimplementaweb-basedloginsystem.

ASP.NETmembershipwasdesignedtoaddresstheseandother

shortcomings.ThemembershipfeaturesofASP.NETmakeit

easytoimplementapassword-protectedwebsite(orpartofa

site)thatiscompletelyweb-based.



TheMembershipProvider



ASP.NEThasmanybuilt-incapabilitiesthatdeveloperscantake

advantageofwithoutwritinganycode.Partofwhatmakesthat

possibleisacollectionofpre-builtcomponentscalledproviders

thatsupplyaspecifictypeoffunctionality.

ASP.NETmembershipusesabuilt-inmembershipproviderto

makeitsfeaturesavailabletoyou.Themembershipprovider

dictatesspecificsabouthowthemembershipsystemis

implemented.Forexample,someofthecapabilitiesprovidedby

thedefaultmembershipproviderare

AconnectiontoaSQLServer2005ExpressEdition

database.

Passwordstrengthandlengthrequirements.

Logincapabilityforthewebsiteortheprotectedpartofa

site.

Capabilitytocreateusersandforuserstocreatetheirown

accounts.

Abilityforuserstoretrievealostpasswordorresetit.

Accesstocontrolledcontentbasedonusersand/orgroups.

Someofthecapabilitiesofthedefaultmembershipprovidercan

bemodified.Forexample,youcanmodifythedatabase

connectionstringsothemembershipproviderusesaSQL

Server2005orSQLServer2000databasewithoutchanging

providers.However,somechangesrequirethatyoueither

modifythedefaultprovideroruseadifferentprovider.

SupposeyouwanttouseaMySQLdatabaseforyour

membershipsystem.Todothat,youneedtouseacustom

providertoprovidethatfunctionality.However,thatcustom

providerhastoprovideonlytheportionofthemembership

systemthatcommunicateswiththedatabase.Otherlogin

functionalitycanbeprovidedbyexistingASP.NETmembership

features.



Tip

Thecreationofcustommembershipprovidersisfar

beyondthescopeofthisbook.However,inmostcases,

ifyoudesirespecificfunctionality,youcanfindathirdpartyproviderthatyoucanuseatnocharge.

Forthepurposesofthisbook,youdon'treallyneedto

understandtheprovidermodelorhowitallworks,butit's

helpfulinseeingthebigpicturetoknowthatthefunctionalityof

yourmembershipsystemissuppliedbythemembership

provider.



UsingtheDefaultMembershipDatabase

Bydefault,themembershipproviderusesSQLServer2005

ExpressEdition.ASP.NETautomaticallycreatestheSQLServer

2005ExpressEditiondatabaseintheApp_Datafolderofyour

website,asshowninFigure12.1.

Figure12.1.Thedefaultmembershipdatabaseiscreated

intheApp_Datafolderofyourwebsite,asshownhere.



ASP.NETcreatesthedefaultmembershipdatabasethefirsttime

thatyouinteractwithoneoftheASP.NETLogincontrolsinthe

browserorifyouadministerthewebsitetoaddusers,roles,

andsoon.

Formoreinformationonadministeringusersand

roles,see"UsersandRoles,"p.186.



Weusethedefaultmembershipdatabaseaswecompletethe

webapplicationinthisbook.



UsingSQLServer2000orSQLServer

2005forMembership

ASQLServer2005ExpressEditiondatabaseisfineformany

users,butifyouexpectmorethanafewdozenpeopletouse

yourwebsiteatanyonetime,youmightwanttouseamore

robustdatabaseengine.Inthosecases,it'squitesimpleto

configurethemembershipprovidertouseSQLServer2000or

SQLServer2005.

Note

Yourhostingcompanymayalsoprovidearestrictionon

usingSQLServer2005ExpressEdition.Ifyou'renot

sureaboutthekindsofdatabasesyoucanusewith

ASP.NETmembership,checkwithyourhosting

company.

Tip

You'renotlimitedtousingMicrosoft'sdatabase

technologies.Infact,manywebdesignerspreferMySQL

becauseit'softenmoreaffordabletohost.Youcan

downloadanASP.NET2.0membershipproviderand

instructionsforusingMySQLat

www.codeproject.com/aspnet/MySQLMembershipProvider.asp

Thisproviderwillworkperfectlyfineona.NET

Framework3.5application.

IfyouchoosetousetheMySQLproviderfromTheCode

Project,youcanskipthissectionbecauseitdoesn't

applytoMySQL.



ConfiguringtheDatabase

ASP.NETcomeswithautilitycalledaspnet_regsql.exefor



configuringaSQLServerdatabaseforusewithASP.NET

membership.Theaspnet_regsql.exeutilitycanbeusedasa

command-linetool,butitalsooffersawizardinterfacethat

makesitfastandeasytoconfigureyourdatabaseforASP.NET

membership.

Note

IfyouneedtoaddASP.NETmembershipservicestoa

SQLServerinstanceprovidedbyyourhostingcompany,

thecompanyneedstousetheaspnet_regsqltool.You

can'tconfigureityourself.



ToconfigureSQLServer2000orSQLServer2005forASP.NET

membership,followthesesteps:

1. Createanew,blankdatabase.



Note

Formoreinformationonhowtocreatea

newblankdatabaseinyourversionofSQL

Server,seeSQLServerBooksOnline,which

comeswithSQLServer.

2. ClicktheWindowsStartbuttonandselectAllPrograms.

ClicktheAccessoriesprogramgroupandselectCommand

Prompttolaunchacommandprompt.

3. Atthecommandprompt,typethefollowingcommandand

pressEnter:



cd%windir%\microsoft.net\framework\v2.0*



4. Atthecommandprompt,typeaspnet_regsqlandpress

EntertolaunchtheASP.NETSQLServerSetupWizard,as

showninFigure12.2.



Figure12.2.TheASP.NETSQLServerSetup

Wizardisafastandconvenientwaytoadd

ASP.NETmembershipcapabilitiestoan

existingdatabase.

[Viewfullsizeimage]



5. ClickNexttoproceedtothenextstep.

6. SelecttheConfigureSQLServerforApplicationServices

radiobutton,asshowninFigure12.3,andclickNext.



Figure12.3.TheASP.NETSQLServerSetup



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 12. Configuring a Membership Database

Tải bản đầy đủ ngay(0 tr)

×