个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx

上传人:b****1 文档编号:3090701 上传时间:2023-05-05 格式:DOCX 页数:14 大小:24.51KB
下载 相关 举报
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第1页
第1页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第2页
第2页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第3页
第3页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第4页
第4页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第5页
第5页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第6页
第6页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第7页
第7页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第8页
第8页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第9页
第9页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第10页
第10页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第11页
第11页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第12页
第12页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第13页
第13页 / 共14页
个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx

《个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx》由会员分享,可在线阅读,更多相关《个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx(14页珍藏版)》请在冰点文库上搜索。

个性化定制ASP NET Whidbey中英文对照外文翻译文献.docx

个性化定制ASPNETWhidbey中英文对照外文翻译文献

中英文资料对照外文翻译

 

原文:

GetPersonalwithASP.NETWhidbey

ConfiguretheProvider

Withbothpersonalizationandmembership,thefirststepisconfiguringtheproviderthatyouwillusetostorethepersonalizationormembershipdata.ThoughyoucancreatetheMicrosoftAccessorMicrosoftSQLServer™databaseandaddthenecessaryconfigurationelementsmanually,theeasierwayistousetheASP.NETWebSiteAdministrationtool,Notethattoconfigureanapplicationsuccessfully,youmustbeloggedinusinganaccountwithadministratorrights(youalsocanlaunchMicrosoftVisualStudio®.NETwithanadministrator-levelaccountusingRunAs...andlaunchtheWebSiteAdministrationtoolfromthebuttoninSolutionExplorer).

TheASP.NETWebSiteAdministrationtoolprovidesthemeanstoconfigurepersonalizationandmembershipfeatures(theMembershipdatastoreisconfiguredusingtheSecuritytab),aswellasreportsanddata-accessfeatures.

TocreateanAccess.mdbfileforstoringpersonalizationdata,youneedtoopentheWebSiteAdministrationtool;thefile,namedAspNetDB.mdb,willbecreatedautomaticallyinafoldernamedDATA.AlthoughnotenabledinthebuildofVisualStudioagainstwhichthisarticlewaswritten,theWebSiteAdministrationtoolcontainsanentiresectiondevotedtoconfiguringpersonalizationsettings.Inalatersection,I'llwalkyouthroughaddingthenecessaryconfigurationsectionsbyhand.

YouconfiguretheprovidertouseformembershipservicesusingtheSecuritytaboftheWebSiteAdministrationtool.TheeasiestwaytoconfigurethemembershipprovideristoselecttheSecuritySetupWizard.I'llwalkyouthroughthisprocessmomentarily.

Atthispoint,themembershipdatabasewillbecreated,andthenecessaryconfigurationelementswillbeaddedtotheweb.configfile.Allyouneedtodofromhereisadduserstothedatabase(whichyoucandousingtheWebSiteAdministrationtool,orthemembershipAPIs),setauthorizationrestrictionsonpagesasdesired,andcreatealoginpage.

Itisimportanttonotethatthedatabasestructurethatiscreatedforbothpersonalizationandmembershipisthesame,soyoucan(andforefficiency'ssake,should)usethesameproviderforbothpersonalizationandmembership.Thatsaid,itispossibletouseadifferentproviderforpersonalizationthanformembership,andvice-versa,ifyouprefer.

Inadditiontothebuilt-inAccessandSQLServerproviders,youcancreateyourowncustomprovidersandconfigureyourapplicationstousetheseproviders.So,ifyoualreadyhaveauser-credentialdatabasethatyou'renotwillingtopartwith,ASP.NETallowsyoutousethatandstillgetthebenefitsthatmembershipservicesprovide.Notethatatthetimeofthiswriting,theactualmeansforcreatingcustomproviderscouldundergosomechangesstill,soI'llsaveademonstrationofcreatingcustomprovidersforafuturearticle.

How'stheDataStored?

UseServerExplorertoseehowdataisstoredinAspNetDB.mdb.JustcreateadatabaseconnectiontoAspNetDB.mdbanddragtablesfromtheconnectiontoapageinyoursite.VisualStudiowillcreateaGridViewcontrolandbindittoanAccessDataSourcecontrol(notethattheASP.NETworkerprocessmusthaveread-writepermissionsonthefoldercontainingthedatabaseforthistowork).Ifyouhavedifficultybrowsingpagesintheapplication,closetheconnectioninServerExplorerbeforebrowsingthepages.

PersonalizationandMembership:

Whatdotheymean?

Personalizationandmembershipenableyoutocontrolaccesstoyourapplication,aswellastostoreandretrieveinformationaboutusersofyourapplication,includinganonymoususers.Youcancustomizetheappearanceandbehaviorofyourapplicationbasedonthisinformation,andyouevencanallowuserstostoreprofileinformation,suchasashoppingcart,whilebrowsinganonymously,andlatereasilymigratethatinformationtotheirpersonalprofileswhentheylogin.

Personalizationallowsyoutostoreprofileinformationaboutusersofyourapplicationinapersistentdatastore.Personalizationsupportsapluggabledata-providerlayerandasetofAPIsforstoringandretrievingprofileinformationinastronglytypedfashion.Personalizationallowsyoutospecifyoneormorearbitrarypropertiestobestoredinauser'sprofile.Youcanspecifythetypeofeachproperty(whichcanbeasystemtypeorauser-definedtypeorcustomclass),aswellaswhetherthepropertyistrackedforanonymoususers,whetherthepropertyisread-onlyorread-write,andmore.

Personalizationalsocanbeintegratedwithmembershipservicestoprovideaunifiedsolutionforusermanagement,login,andprofile-informationstorage.Bydefault,theASP.NETpersonalizationsystemassociatesprofileinformationwiththeidentitywithwhichtheuserauthenticates,accessiblethroughHttpContext.Current.User.Identity.Name.IfyouareusingASP.NETmembershipservicesforuser-credentialmanagement,thenanytimeauserlogsintoyourapplication,hisorhermembershipidentityautomaticallywillbestoredinHttpContext.Current.User.Identity.Name,andallprofileinformationassociatedwiththatidentitywillbeavailabletotheapplication.SupportforstoringprofileinformationforanonymoususersisnotenabledbydefaultandrequiresaddinganelementtotheWeb.configfilefortheapplication,aswellasspecificallymakingeachdesiredpropertyavailableforanonymoususers.

Membershipdescribesthesetoftechnologies,including(aswithpersonalization)aback-endproviderforstoringdata;asetofAPIsformanagingusersandlogins,andsoon;andcontrolsthatallowyoutoadduser-credentialstorageandrelatedfunctionalitytoyourapplicationwithnolinesofcode.

Usercredentialsarestoredinaback-endmembershipdatabasespecifiedbythedataprovideryouconfigureinWeb.config.ASP.NETWhidbeyshipswithAccess,andSQLServerprovidersareavailableoutofthebox.Oncemembershipisconfigured,andusersareaddedtothemembershipdatastore,addingloginfunctionalitytotheapplicationcanbeassimpleasdraggingasinglecontroltoapageintheapplication.TheASP.NETlogincontrols(Login,LoginView,LoginStatus,LoginName,andPasswordRecovery)containallofthelogicnecessarytovalidatecredentialsandperformanynecessaryredirection,andsoon,andaredesignedtointegratewithmembership.

AddPersonalizationProperties

Todemonstratepersonalization,nextI'llshowyouhowtoaddsomepropertydefinitionsandstoreandretrievethemfromapage.Oneofthepropertieswillallowtheusertochooseapagethemethatwillbeusedwhenevertheuservisits.ThemesareanewfeatureofASP.NETWhidbeythatallowyoutomodifythelookandfeelofanentiresitewithasimpleconfigurationsettingorafewlinesofcode.

OpenWeb.configandaddthefollowing,directlyaftertheelement:

type=

"System.Collections.Specialized.StringCollection"

allowAnonymous="true"

serializeAs="Xml"/>

Theelementisrequiredinordertoallowanonymousaccesstoanypersonalizationproperties.Thepersonalizationsectioncontainstwoproperties,bothofwhichusetheallowAnonymousattributetoenablethepropertiestobetrackedforuserswhoarenotloggedin.Thefirstproperty,Theme,doesnotspecifyatype,soitwillbetreatedasastring.Thesecondproperty,FavoriteColors,specifiestheStringCollectionclassasitstype.AnyattempttostoredatathatisnotcompatiblewiththeStringCollectionclassinthispropertywillresultinanexceptionbeingthrown.TheserializeAsattributeallowstheStringCollectiontobestoredinthedatabaseasanXMLstring.

CreateanewWebFormintheprojectcalledDefault.aspx.Then,switchtoDesignviewandaddthecontrols,withtheirpropertiessetasspecified.

Table1.Propertiestobeassignedtothecontrolsaddedintheprecedingexamplestep

Control

Properties

DropDownList

ID=Themes

Button

ID=SetTheme

Text=SetTheme

TextBox

ID=textFavColor

Button

ID=AddColor

Text=AddColor

ListBox

ID=listFavColors

SelecttheDropDownListcontrolandinthePropertieswindow,scrolldowntoandselecttheItemsproperty.ClicktheellipsisbuttontoopentheCollectionEditor.Addtwoitems,onewiththetextandvaluesettoBasicBlueandonesettoSmokeAndGlass,andthenclickOK.Double-clicktheSetThemebuttonandaddthefollowingcodetotheeventhandler:

Profile.Theme=Themes.SelectedValue

AddthefollowingeventhandlertotheServerCodewindow:

SubPage_PreInit(ByValsenderAsObject,_

ByValeAsSystem.EventArgs)

IfProfile.Theme=""Then

IfRequest.Form("Themes")<>""Then

Page.Theme=Request.Form("Themes")

EndIf

Else

Page.Theme=Profile.Theme

EndIf

EndSub

Thiscodeisrequiredtosetthepage'stheme,whichmustbesetinthePage_PreIniteventorearlier.Thecodecheckstoseewhetherathemeisalreadysetfortheuser'spersonalizationprofileandusesthattheme.Ifnothemeexists,thecodecheckstoseeiftheuserhassubmittedthepagewithanewthemechoiceand,ifso,usesthenewtheme.Otherwise,nothemewillbeapplied.

SwitchbacktoDesignviewanddouble-clicktheAddColorbutton.Addthefollowingcodetotheeventhandler:

DimFaveColorAsString=_

Server.HtmlEncode(textFavColor.Text)

DimFaveColorsAsNew_

System.Collections.Specialized.StringCollection

Profile.FavoriteColors.Add(FaveColor)

DisplayFavoriteColors()

AddthefollowingsubroutinejustbelowtheAddColor_Clickhandler:

SubDis

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2