Tải bản đầy đủ - 0 (trang)
Part II: Creating ASP.NET Applications and Web Forms

Part II: Creating ASP.NET Applications and Web Forms

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

Chapter8.CreatingWebsites

INTHISCHAPTER

TheStructureofanASP.NETWebsite116

CreatingaWebApplicationinVisualWebDeveloper119

StartOptionsinVisualWebDeveloper124



TheStructureofanASP.NETWebsite

Afewyearsago,acommonquestionoftenaskedofpeoplein

thebusinesscommunitywas"Doyouhaveawebpage?"Back

then,havingapresenceontheWeboftenmeanthavinga

singlepageorasmallgroupofunrelatedpagesfilledwithtrivial

information.

Todaywebsitesaremadeupofmuchmorethanasinglepage.

Theyfrequentlycontainpagesthatinteractwithdatabases,

formsthatuserscanusetopostmessagesorsendmessagesto

thewebsite'sowner,andotherinteractivefeatures.

Tip

AnASP.NETwebsiteisoftenreferredtoasaweb

application.



SpecialFoldersinanASP.NETApplication

Inadditiontotheimages,pages,andotherfilesthatmakeupa

website,therearealsonumerousspecialfoldersthatyoumight

findinsideanASP.NETwebapplication.



ThebinFolder

ThebinfolderisaspecialfolderthatcontainscompiledDLLson

whichthewebapplicationrelies.Dependingonhowyour

ASP.NETapplicationisconfigured,youmayormaynothavea



binfolder.



TheApp_CodeFolder

TheApp_Codefolderisaspecialfolderthatcontainscodefiles

thatdefineclassesusedinyourWebforms.Youcancreateyour

ownclassesforyourownpurposesbydefiningtheminsidea

codefile.ThatcodefilecanthenbeaddedtotheApp_Code

foldersothatASP.NETcanautomaticallymakeyourclass

availabletoallyourWebforms.

FormoreinformationonclassesinanASP.NET

website,seeChapter2,"ASP.NETCodeModels."



Note

Foracompleteexplanationofcreatingclassesforuse

byyourWebforms,readSamsTeachYourselfASP.NET

2.0in24Hours,CompleteStarterKitfromSams

Publishing.



Tip

Acodefileisafilethatcontainsonlyserver-sidecode

andisnotrelatedtoaWebform.Codefilesthatare

writteninC#havea.csfileextensionandcodefiles

thatarewritteninVisualBasichavea.vbfile

extension.



TheDataFolder

Thedatafolder(namedApp_Databydefault)containsfilebaseddatabasesforusebyyourASP.NETapplication.Most



commonly,thesedatabasesareSQLServer2005Express

Editiondatabases.

Youcancreateyourowndatabasesandstoretheminthe

App_Datafolder.ASP.NETalsocreatesdatabasesautomatically

insomecasesandplacesthemintheApp_Datafolder.For

example,ifyouusetheASP.NETmembershipfeatures,an

ASPNETDB.MDFfileisautomaticallycreatedintheApp_Data

foldertostoreyourmembershipdata.

FormoreinformationonusingASP.NET

membershipfeatures,see"Configuring

Authentication,"p.186.



Tip

TheApp_Datafolderisautomaticallyconfiguredwith

theproperpermissionsforyourASP.NETapplicationto

accessthedatabasesstoredwithinit.



TheApp_GlobalResourcesFolder

TheApp_GlobalResourcesfolderisusedtostoreresourcefiles

thatareusedbyyourASP.NETapplications.Resourcefilesare

XMLfileswitha.resxfileextensionthatcontainstringsthat

yourapplicationcanloaddynamically.Theyareusuallyusedin

caseswhereanapplicationneedstodisplaytextdynamicallyin

differentlanguages.

WhenyoucreateanewresourcefileinVisualWebDeveloper,

youarepromptedtosavetheresourcefileintothe

App_GlobalResourcesfolder.

Note



Formoreinformationonusingresourcefilesin.NET

Frameworkapplications,seetheInformITNetwork

websiteatwww.informit.com.



TheApp_LocalResourcesFolder

TheApp_LocalResourcesfolderisalsousedtostoreresource

files,butunliketheApp_GlobalResourcesfolder,the

App_LocalResourcesfoldercanbelocatedatanylevelinthe

websiteandcontainsresourcesthatarenotusedgloballyby

theapplication.Eachlocalresourcefileisusedbyaspecific

ASP.NETpageandsharesthepage'sname.Forexample,alocal

resourcefileforapagecalledinfo.aspxmightbecalled

info.aspx.resx.Ifthelocalresourcefilecontainsresourcesfor

aspecificlocale,thefilewillcontainthelocalecodeaswell.For

example,aresourcefilefortheinfo.aspxpagethatcontains

resourcestringsforFrancewouldbecalled

info.aspx.fr.resx.

Note

TherecanbemanyApp_LocalResourcesfoldersatany

placewithinawebapplication.Therecanbeonlyone

App_GlobalResourcesfolder,anditmustbelocatedin

theapplicationroot.



TheApp_WebReferencesFolder

TheApp_WebReferencesfoldercontainsvariousfilesthatare

usedforcreatingreferencestoASP.NETwebservices.

FormoreinformationonusingASP.NETweb

services,seeChapter25,"CreatingandTestingan

ASP.NETWebService."



TheApp_BrowsersFolder

ASP.NETattemptstorendercodethatworkscorrectlyinthe

browserthatinitiatestherequesttoyourapplication.Inmost

cases,thecodethatASP.NETgeneratesrenderscorrectlyonall

browsers,butinsomecasesyouneedtoletASP.NETknow

explicitlywhatcapabilitiesarepresentinabrowserthatis

accessingyoursite.

Tip

Everybrowsersendswhat'scalledauser-agentstring

thatidentifieswhatkindofbrowseritis.ASP.NETuses

thebrowser'suser-agentstringtoidentifydifferent

browsers.



ASP.NET2.0introducedanewtypeoffilecalledabrowser

definitionfile.AbrowserdefinitionfileisanXMLfilewitha

.browserextensionthatcontainsinformationregardingthe

capabilitiesofoneormorebrowsers.Insomecases,the

browserdefinitionfilecontainsinformationaboutwhich

browserssupportfeaturessuchascookies,JavaScript,andso

on.

Inothercases,theremaybemoreintricaterequirementsfor

therenderingofaspecificcontrol.Forexample,supposethat

usersarebrowsingyourwebsitefromabrowserrunningona

cellphoneandaparticularASP.NETcontrolisnotrendering

correctly.Insuchcases,adevelopercancreateaspecialclass

calledacontroladapterthatmanageshowASP.NETrendersthe

controlforthatparticularbrowser,andthemappingofthe

controladaptertothecontroliscreatedinsideabrowser

definitionfile.

Note



Youcanfindexcellentcoverageofcontroladaptersby

readingProfessionalASP.NET2.0ServerControland

ComponentDevelopmentfromWroxProfessional

Guides.



TheApp_ThemesFolder

TheApp_ThemesfolderisthestorageareaforASP.NETthemes

thatareavailableforyouruseinyourwebapplication.The

App_Themesfoldercontainsonesubfolderforeachavailable

theme.

FormoreinformationonusingthemesinASP.NET,

seeChapter19,"UsingASP.NETThemesand

Skins."



Creatingoneofthesefoldersinyourwebapplicationiseasy

withVisualWebDeveloper.Simplyselectyourprojectin

SolutionExplorer(thetop-levelfolderofyourwebapplication)

andselectWebsite,AddASP.NETFolderfromthemenu,as

showninFigure8.1torevealamenuoffoldernames.

Alternatively,youcanright-clickontheprojectinSolution

ExplorerandselectAddASP.NETFolderfromthemenu.

Figure8.1.AddingspecialASP.NETfoldersiseasyin

VisualWebDeveloper.Makesureyoufirstselectthe

projectinSolutionExplorer.

[Viewfullsizeimage]



PartII:CreatingASP.NETApplications

andWebForms







8CreatingWebsites

9CreatingASP.NETWebForms



Chapter8.CreatingWebsites

INTHISCHAPTER

TheStructureofanASP.NETWebsite116

CreatingaWebApplicationinVisualWebDeveloper119

StartOptionsinVisualWebDeveloper124



TheStructureofanASP.NETWebsite

Afewyearsago,acommonquestionoftenaskedofpeoplein

thebusinesscommunitywas"Doyouhaveawebpage?"Back

then,havingapresenceontheWeboftenmeanthavinga

singlepageorasmallgroupofunrelatedpagesfilledwithtrivial

information.

Todaywebsitesaremadeupofmuchmorethanasinglepage.

Theyfrequentlycontainpagesthatinteractwithdatabases,

formsthatuserscanusetopostmessagesorsendmessagesto

thewebsite'sowner,andotherinteractivefeatures.

Tip

AnASP.NETwebsiteisoftenreferredtoasaweb

application.



SpecialFoldersinanASP.NETApplication

Inadditiontotheimages,pages,andotherfilesthatmakeupa

website,therearealsonumerousspecialfoldersthatyoumight

findinsideanASP.NETwebapplication.



ThebinFolder

ThebinfolderisaspecialfolderthatcontainscompiledDLLson

whichthewebapplicationrelies.Dependingonhowyour

ASP.NETapplicationisconfigured,youmayormaynothavea



binfolder.



TheApp_CodeFolder

TheApp_Codefolderisaspecialfolderthatcontainscodefiles

thatdefineclassesusedinyourWebforms.Youcancreateyour

ownclassesforyourownpurposesbydefiningtheminsidea

codefile.ThatcodefilecanthenbeaddedtotheApp_Code

foldersothatASP.NETcanautomaticallymakeyourclass

availabletoallyourWebforms.

FormoreinformationonclassesinanASP.NET

website,seeChapter2,"ASP.NETCodeModels."



Note

Foracompleteexplanationofcreatingclassesforuse

byyourWebforms,readSamsTeachYourselfASP.NET

2.0in24Hours,CompleteStarterKitfromSams

Publishing.



Tip

Acodefileisafilethatcontainsonlyserver-sidecode

andisnotrelatedtoaWebform.Codefilesthatare

writteninC#havea.csfileextensionandcodefiles

thatarewritteninVisualBasichavea.vbfile

extension.



TheDataFolder

Thedatafolder(namedApp_Databydefault)containsfilebaseddatabasesforusebyyourASP.NETapplication.Most



commonly,thesedatabasesareSQLServer2005Express

Editiondatabases.

Youcancreateyourowndatabasesandstoretheminthe

App_Datafolder.ASP.NETalsocreatesdatabasesautomatically

insomecasesandplacesthemintheApp_Datafolder.For

example,ifyouusetheASP.NETmembershipfeatures,an

ASPNETDB.MDFfileisautomaticallycreatedintheApp_Data

foldertostoreyourmembershipdata.

FormoreinformationonusingASP.NET

membershipfeatures,see"Configuring

Authentication,"p.186.



Tip

TheApp_Datafolderisautomaticallyconfiguredwith

theproperpermissionsforyourASP.NETapplicationto

accessthedatabasesstoredwithinit.



TheApp_GlobalResourcesFolder

TheApp_GlobalResourcesfolderisusedtostoreresourcefiles

thatareusedbyyourASP.NETapplications.Resourcefilesare

XMLfileswitha.resxfileextensionthatcontainstringsthat

yourapplicationcanloaddynamically.Theyareusuallyusedin

caseswhereanapplicationneedstodisplaytextdynamicallyin

differentlanguages.

WhenyoucreateanewresourcefileinVisualWebDeveloper,

youarepromptedtosavetheresourcefileintothe

App_GlobalResourcesfolder.

Note



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

Part II: Creating ASP.NET Applications and Web Forms

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

×