Tải bản đầy đủ - 0 (trang)
Chapter 14. Deploying a Web Application

Chapter 14. Deploying a Web Application

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

DeploymentTools

The.NETFrameworksimplifiesapplicationdeploymentby

makingzero-impactinstallationandXCOPY/FTPdeployment

feasible.Youcaninstalla.NETapplicationthatusesonly

managedcodeandprivateassembliesbysimplycopyingallthe

necessaryfilestothedesireddestination.NoRegistryentries

needtobecreated,andnofilesneedtobecopiedtothe

Windowssystemdirectory(therebycausingzeroimpactonthe

configurationofthetargetmachine).

However,someinstallationtasks,suchasthoselistedhere,are

difficultorimpossibletoachievewithXCOPYorFTP:

CreatingIISsitesorvirtualdirectories

Copyingfilestorelativepathsonthetargetmachinethat

differfromthepathsonthesourcemachine

AddingassembliestotheGAC

Creatingorconfiguringdatabasesduringtheinstallation

Addingcustomeventlogsorperformancecounterstothe

targetmachine

Checkingwhetherthe.NETFrameworkisinstalledonthe

targetmachine

Allowinglicensekeymanagementanduserregistration

Forthesescenarios,thepreferredalternativeistousea

MicrosoftWindowsInstaller-basedinstallationprogram.



Microsoft'sWindowsInstallerisaninstallationandconfiguration

servicebuiltintotheWindowsoperatingsystem.Itgivesyou

completecontrolovertheinstallationofanapplication,a

component,oranupdate.



MethodsofDeployment

Afteryouhavecreatedasetuppackage,youcandeployyour

applicationfromanylocationthat'saccessibletoallitspotential

users.TheWebapplicationsexamrequiresyoutoknowabout

thetwotypesofdeploymentdiscussedinthefollowingsections.



DeploymentviaRemovableMedia

Themostcommonexamplesofremovablemediaarefloppy

disks,CD-ROMs,andDVDs.DeploymentprojectsinVisual

Studio.NETcanbeusedtocreatepackagesdividedacross

multiplefileseachwithasizespecifiedbythedeveloper.These

smallfilescanthenbecopiedtoremovablemediaand

distributedtousers.

TocreateaWebsetupprojectforremovablemedia,createa

Websetupprojectandintheproject'spropertypages,change

thePackagefilesoptiontoIncabinetfile(s).Thisaction

alsoenablestheCabSizeoption,whereyoucanspecifythesize

ofthecabfilesdependingonyourmediasize.



Web-basedDeployment

Web-baseddeploymentisthemostpopularformof

deployment,especiallyforsmallapplications.Withthegrowth

ofhigh-speedInternetconnections,thisformofdeploymentis

inmuchhigherdemandcomparedtoremovablemedia.Itoffers

severaladvantagesoverotherformsofapplicationdeployment,

including

Itreducesthecostsofmedia,replication,anddistribution.



Managementofsoftwareupdatesissimple.Youcan

programanapplicationtoautomaticallycheckforupdates

ontheWeb,oryoucaninstructuserstodownloadan

updatepackagefromaWebpage.

ForWeb-baseddeployment,afterthesetupfilesarecreated,

ratherthancopyingthemtoaremovablemedia,youcopythem

toavirtualdirectoryonaWebserver.Youmightalsowantto

password-protectthedeploymentWebsitesothatonly

authorizeduserscandownloadtheapplication.Youcanthen

installtheapplicationbynavigatingtotheURLofthe

setup.exefile.



ImplementingMirroring

Theprocessofswitchingauserinterfacebetweenaleft-to-right

language,suchasGermanorEnglish,andaright-to-left

language,suchasHebreworArabic,iscalledmirroring.

The.NETFrameworkofferssupportformirroringinWebforms

throughtheHTMLdirattribute,asshowninthefollowingcode

sample:



SettingtheHTMLdirattribute(whichcanalsobeseton

individualcontrols)handlesmostofthefacetsofthemirroring

processautomatically.Controlsfillfromrighttoleftasyou

entertext,andtheDropDownList,RadioButton,andCheckBox

controlsreversetheirappearances.

Ifyouwanttomirrorpartofaform,youcansetthedirpropertytortl

onindividualcontrolsinsteadofontheentireform.



DiscoveringWebServices

OneoftheproblemswithWebservicesissimplyfindingthem.

Evenifyoufindthem,youneedsomewaytodeterminewhich

messagestheyacceptandwhichservicestheyprovide.The

usualtermforthisprocessisdiscovery,whichencompasses

bothfindingWebservicesanddeterminingtheirinterfaces.



DiscoandUDDI

DiscoisaMicrosoftstandardforthecreationofdiscovery

documents.ADiscodocumentiskeptatastandardlocationon

aWebservicesserverandcontainspathsandinformationfor

retrievingotherusefulinformation,suchastheWSDLfilethat

describesaservice.Discoisgenerallynotusedoutsidethe.NET

world.

UDDIisamethodforfindingservicesbyreferringtoacentral

directory.ThesecanbeWebservices,URLsforinformation,or

anyotheronlineresource.UDDIregistriesaresitesthatcontain

informationthatisavailableviaUDDI;youcansearchsucha

registrytofindinformationaboutWebservices.

UDDIregistriescomeintwoforms:publicandprivate.Apublic

UDDIregistryisavailabletoeveryoneviatheInternet,andit

servesasacentralrepositoryofinformationaboutWeband

otherservicesforbusinesses.AprivateUDDIregistryfollows

thesamespecificationsasapublicUDDIregistry,butitis

locatedonanintranetfortheuseofworkersatoneparticular

enterprise.

TheUDDIspecificationisbeingdevelopedjointlybyseveralindustry

partners,includingMicrosoftandIBM.Formoreinformationandapublic

directory,visitwww.uddi.org.



UsingtheWebServicesDiscoveryTool

(disco.exe)

WhenyousetaWebreferenceinVisualStudio.NET,the

softwareautomaticallyhandlesthedetailsofdiscoveryforyou.

Butyoucanalsogetintothedetailsoftheprocessyourself.

Oneofthetoolsincludedinthe.NETFrameworkSDK(andalso

inVisualStudio.NET)istheWebServicesDiscoverytool,

disco.exe.Forexample,whenyouissuethedisco

http://live.capescience.com/wsdl/AirportWeather.wsdl

command,thetoolcontactstheCapeScienceAirportWeb

servicetocreatethese:AirportWeather.wsdland

results.discomap.



TheWebServicesDiscoverytool(disco.exe)retrievesthediscovery

documentiftheWebserviceincludesastaticdiscoverydocument

(.discofile).The.discofileisanXMLfilecontainingusefulURLs,

includingtheURLfortheWSDLfiledescribingtheservice,theURLfor

thedocumentationoftheservice,andtheURLtowhichSOAPmessages

shouldbesent.



NavigationBetweenPages

AtypicalWebapplicationisacollectionofWebpageslinkedto

eachother.YoucanusetheHyperLinkcontroltonavigatetoa

differentWebpagewhenthehyperlinkisclicked.Ifyouneedto

navigatetoaWebpageprogrammatically,youcanusethe

followingmethodsprovidedbyASP.NET:

Response.Redirect()

Server.Transfer()

Server.Execute()



TheResponse.Redirect()Method

TheResponse.Redirect()methodcausesthebrowserto

connecttothespecifiedURL.WhentheResponse.Redirect()

methodiscalled,itcreatesaresponsewhoseheadercontainsa

302(ObjectMoved)statuscodeandthetargetURL.Whenthe

browserreceivesthisresponsefromtheserver,itusesthe

headerinformationtogenerateanotherrequesttothespecified

URL.WhenusingtheResponse.Redirect()method,the

redirectionoccursattheclientsideandinvolvestworoundtrips

totheserver.

UsingtheResponse.Redirect()methodisrecommendedin

thefollowingcases:

YouwanttoconnecttoaresourceonanyWebserver.

Youwanttoconnecttoanon-ASPXresource(suchasan



HTMLfile).

YouwanttopassaquerystringaspartoftheURL.



TheServer.Transfer()Method

TheServer.Transfer()methodtransferstheexecutionfrom

thecurrentASPXpagetothespecifiedASPXpage.Thepath

specifiedtotheASPXpagemustbeonthesameWebserver

andmustnotcontainaquerystring.

Whenthistransferoccurs,executionofthecurrentASPXpage

terminatesandcontrolistransferredtoanotherASPXpage.The

newASPXpagestillusestheresponsestreamcreatedbythe

priorASPXpage.TheURLinthebrowserstillshowstheoriginal

pagebecausetheredirectionoccursontheserversideandthe

browserremainsunawareofthetransfer.

WhenyouwanttotransfercontroltoanASPXpageresidingon

thesameWebserver,youshoulduseServer.Transfer()

insteadofResponse.Redirect()becauseServer.Transfer()

avoidsanunnecessaryroundtripandprovidesbetter

performanceanduserexperience.

ThedefaultuseoftheServer.Transfer()methoddoesnot

passtheformdataandthequerystringoftheoriginalpage

requesttothepagereceivingthetransfer.However,youcan

preservetheformdataandquerystringoftheoriginalpageby

passingatruevaluetotheoptionalsecondargumentofthe

Server.Transfer()method.Thesecondargumenttakesa

Booleanvaluethatindicateswhethertopreservetheformand

querystringcollections.

IntheServer.Transfer()method,whenyouchoosetopreservethe

formandquerystringcollections,youneedtobeawareofonething:

Thedestinationpagecontainstheformandquerystringcollectionsthat



werecreatedbytheoriginalpage.Asaresult,thehidden

__VIEWSTATEfieldoftheoriginalpageisalsopreservedintheform

collection.Theviewstateispagescopedandisvalidforaparticular

pageonly,whichcausestheASP.NETMACtoannouncethattheview

stateofthenewpagehasbeentamperedwith.Therefore,whenyou

choosetopreservetheformandquerystringcollectionsoftheoriginal

page,youmustsettheEnableViewStateMacattributeofthePage

directivetofalseforthedestinationpage.



TheServer.Execute()Method

TheServer.Execute()methodenablesthecurrentASPXpage

toexecuteaspecifiedASPXpage.However,thepathtothe

specifiedASPXpagemustbeonthesameWebserverandmust

notcontainaquerystring.

AfterthespecifiedASPXpageisexecuted,controltransfers

backtotheoriginalpagefromwhichtheServer.Execute()

methodwascalled.Thistechniqueofpagenavigationis

analogoustomakingamethodcalltoanASPXpage.

ThecalledASPXpagehasaccesstotheformandquerystring

collectionsofthecallingpage.Thus,forthereasonsexplained

intheprevioussection,youmustsettheEnableViewStateMac

attributeofthePagedirectivetofalseonthecalledASPX

page.

Bydefault,theoutputoftheexecutedpageisaddedtothe

currentresponsestream.Thismethodalsohasanoverloaded

versioninwhichtheoutputoftheredirectedpagecanbe

fetchedinaTextWriterobjectinsteadofaddingtheoutputto

theresponsestream.Thishelpsyoucontrolwheretheoutputis

placedontheoriginalpage.



TheoutputreturnedtothebrowserbyServer.Execute()and

Server.Transfer()mightcontainmultipleandtags

becausetheresponsestreamremainsthesamewhileexecutinganother

ASPXpage.Therefore,theoutputthatresultsfromcallingthese

methodsmightcontaininvalidHTMLcode.



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

Chapter 14. Deploying a Web Application

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

×