intro asp net

40
Introduction to ASP.NET • Some references: • Beginning ASP.NET using VB.NET; Wrox; 2002 chpt 2. • Kalata, K, Introduction to ASP.NET – 2002, chpt 1. • Esposito, D. Programming Microsoft ASP.NET, chpt 1. • Morrison, M. and Morrison, J. Database driven web sites (2nd edn). Chpt 6. • VS.NET on line documentation + Quickstart tutorials • What is ASP.NET and how is different from ASP ASP: server side technology for creating dynamic web pages using scripting languages eg vb script. ASP.NET: server side technology for creating dynamic web pages using Fully Fledged programming languages supported by .NET VB.NET: our chosen language for writing ASP.NET pages

Upload: rituah

Post on 23-Nov-2015

40 views

Category:

Documents


1 download

TRANSCRIPT

  • Introduction to ASP.NETSome references:Beginning ASP.NET using VB.NET; Wrox; 2002 chpt 2.Kalata, K, Introduction to ASP.NET 2002, chpt 1.Esposito, D. Programming Microsoft ASP.NET, chpt 1.Morrison, M. and Morrison, J. Database driven web sites (2nd edn). Chpt 6.VS.NET on line documentation + Quickstart tutorialsWhat is ASP.NET and how is different from ASPASP: server side technology for creating dynamic web pages using scripting languages eg vb script.ASP.NET: server side technology for creating dynamic web pages using Fully Fledged programming languages supported by .NETVB.NET: our chosen language for writing ASP.NET pages

  • What is .NET?A Microsoft strategy and new technology for delivering software services to the desktop and to the webComponents include:MS Intermediate Language; all code is complied into a more abstract, trimmed version before execution. All .NET languages are compiled to MSIL the common language of .NETThe CLR- common language runtime; responsible for executing MSIL code; interfaces to Windows and IISA rich set of libraries (Framework Class Libraries) available to all .NET languagesThe .NET languages such as C#, VB.NET etc that conform to CLRASP.NET is how the Framework is exposed to the web, using IIS to manage simple pages of code so that they can be complied into full .NET programs. These generate HTML for the browser.Built on open protocols (XML, SOAP)Future for development of MS & non-MS based systems.Also heading towards the Internet Operating System

  • Common Language Runtime Type SystemCompilers use the runtime type system to produce type compatible components

    ComponentsCompilersCommon Type SystemC#VBC++Runtime Environment

  • Robust And SecureNative code compilationMSIL No interpreterInstall-time or run-time IL tonative compilation

    Code correctness and type-safetyIL can be verified to guarantee type-safetyNo unsafe casts, no uninitialized variables, noout-of-bounds array indexing

    Evidence-based securityPolicy grants permissions based on evidence (signatures, origin)

  • .NET Execution ModelVBVC...ScriptILNative CodeNative CodeCommon Language RuntimeStandard JIT Compiler

  • Common Language Runtime Lightweight Just-in-time compiler:MSIL to Native machine language; Can be ported to numerous platformsThe compiled code is transformed into an intermediate language called the Microsoft Intermediate Language (MSIL or IL)An integer in Visual Basic .NET or an int in C# are converted to the same .NET data type, which is Int32The IL that is created is the same for all languagesThe assembly is the compiled .NET programThe assembly contains the IL along with additional information called metadataMetadata contains information about the assemblyUse the IL Disassembler (ildasm.exe) to view the IL within an assembly

  • Framework OverviewBase Class LibraryCommon Language SpecificationCommon Language RuntimeData and XMLVBC++C#Visual Studio.NETWeb Forms(ASP.NET)JScriptWin Forms

  • .NET Framework ArchitectureCommon Language RuntimeMetadataType SystemExecutionSystem Base FrameworkIONetSecurityServiceProcessADO.NETXMLSQLThreadingSystem.WebWeb ServicesWeb FormsASP.NET Application ServicesSystem.WinFormsControlsDrawingWindows Application Services

  • NamespaceThe base class libraries are organized into logical groupings of code called namespaces A namespace is a hierarchical way to identify resources in .NETThe System object is at the top of the namespace hierarchy, and all objects inherit from itASP.NET: System.Web namespaceWebForms: System.Web.UI namespaceHTML Server Controls: System.Web.UI.Control.HTMLControlASP.NET Server Controls: System.Web.UI.Control.WebControl

  • Importing NamespacesVisual Studio .NET adds references to your projects commonly used namespaces by defaultYou can import the namespaces into your page using the @Import directiveThe following is the syntax for importing a .NET namespace

    Below is a sample of how you would import the ASP.NET Page class

  • Some ASP.NET namespaces

    SystemDefines fundamental data types eg system.stringSystem.CollectionsDefinitions and classes for creating various collectionsSystem.IOFile reading & writing operationsSystem.WebSupport browser/server communicationSystem.Web.UICreates the Page object whenever an .aspx page is requestedSystem.Web.UI.webcontrolsClasses and definitions to create server controls

  • ASP.NET class browserASP.NET provides a means of exposing the .NET Framework and its functionality to the WWWContains a number of pre-built types that take input from .NET types and represents them in a form for the web (such as HTML)Class browser (over 9000 classes; lists the namespaces): http://interdev.csse.monash.edu.au/quickstart/aspplus/samples/classbrowser/vb/classbrowser.aspx

  • ASP.NETThe latest version of ASP is known as ASP.NETVisual Studio .NET is a developer application used to create ASP.NET Web applicationsThere are two main types of Web resources created with ASP.NET applicationsWebForms are ASP.NET pages within an ASP.NET applicationWeb Services are ASP.NET Web pages that contain publicly exposed code so that other applications can interact with themWeb Services are identified with the file extension .asmx

  • WebFormsThe ASP.NET WebForm is separated into two logical areas:The HTML template A collection of code behind the WebForm The HTML template Contains the design layout, content, and the controls Creates the user interface, or presentation layerInstructs the browser how to format the Web pageIs created using a combination of HTML controls, HTML Server controls, Mobile Controls, and ASP.NET controls

  • Server ControlsHTML Server controls are similar to the HTML controls, except they are processed by the serverAdd runat = "server" to the HTML control to transform it into an HTML Server controlHTML control:HTML Server control: YesServer-side programs can interact with the control before it is rendered as a plain HTML control and sent to the browser

  • ASP.NET ControlsASP.NET form controls will create the HTML codeASP.NET Server controls are organized as:ASP.NET Form ControlsData Validation ControlsUser ControlsMobile Controls ASP.NET controls are usually identified with the prefix asp: followed by the name of the controlASP.NET button:

  • HTML Server Vs ASP.NET Server, Controls ASP.NET form controls can interact with client-side events such as when the user clicks on a buttonWhen the event occurs, ASP.NET can trigger a script to run on the serverASP.NET form controls also have different properties than their HTML server control counterparts HTML Server label control Message1.InnerHTML = "Product 1"ASP server label control Message2.Text = "Product 2"

  • User ControlsUser controls are external files that can be included within another WebFormUser controls allow you to reuse code across multiple filesFor example, you can create a user control that displays the a navigation barYou can use this control on the home page; they are often used for creating self-contained code, headers, menus, and footersUser controls replace the functionality of ASP server-side include pagesThey are identified with the file extension .asmx

  • Other ASP.NET Server ControlsData validation controls A series of controls that validate form data without extensive JavaScript programming Mobile controls A series of controls that provide form functionality within wireless and mobile devicesLiteral controls Page content that is not assigned to a specific HTML control such as a combination of HTML tags and text to the browser

  • Server Controls within Visual Studio .NETIn Visual Studio .NET most of the ASP.NET Server controls are located on the Web Forms tab in the toolboxServer controls with Visual Studio.NET

  • The Code BehindServer programs are written in a separate file known as the code behind the pageBy separating the programming logic and presentation layer, the application becomes easier to maintainOnly Server controls can interact with the code behind the pageWritten in any ASP.NET compatible language such as Visual Basic .NET, C#, Perl, or JavaFilename is the same as the WebForm filenameAdd a file extension that identifies the languageVisual Basic .NET use .vb (mypage.aspx.vb)C# use .cs (mypage.aspx.cs)

  • Code Behind fileThe location of the code behind the page is determined via a property that is set on the first line in the page using the @Page directive
  • Compiling the Page ClassThe compiled code behind the page is the class definition for the pageA class is a named logical grouping of codeThe class definition contains the functions, methods, and properties that belong to that classIn Visual Studio .NET the process of compiling a class is called buildingWhen you build the application, you compile the code into an executable fileVisual Studio .NET compiles the code behind the page into an executable file and places the file in the bin directory

  • Page Class EventsThe Page Class consists of a variety of methods, functions, and properties that can be accessed within the code behind the pageThe first time a page is requested by a client, a series of page events occursThe first page event is the Page_Init event which initializes the page control hierarchyThe Page_Load event loads any server controls into memory and occurs every time the page is executed

  • Page class eventsPage_init Page_load Server_Controls Page_prerender Page_Unload

  • Web ServicesWeb Services also provide a means to expose .NET functionality on the web but Web Services expose functionality via XML and SOAP (cf: function calls over the web)

  • Web ServicesIf your business partner is Course Technology and you want to query that companys product catalog from your Web site, you could:Post a linkScrape a Web site (use a program to view a Web site and capture the source code)Provide a Web Service to their catalog applicationWeb Services are used to create business-to-business applicationsWeb Services allow you to expose part or all of your programs over the Internet. The Web Service source file has the extension .asmxA public registry known as UDDI contains registered public Web Services. Third party Web Services are available at http://www.xmethods.com

  • How ASP.NET worksWhen .NET is installed, IIS is configured to look for files with the .aspx extension and to use the ASP.NET module (aspnet_isapi.dll) to handle them.ASP.NET parses the .aspx file and arranges it in a predefined class definition and generates an asp.net page object.The page object generates html that is sent back to IIS and then the browser.NOTE: only .aspx files are parsed (if it is pure html dont save it as an aspx file as it will slow down the server.

  • ASP.NET samplesPage directives:
  • Message2.aspx

    Sub Page_Load() Response.Write ("First ASP.NET Line") Response.Write ("Second ASP.NET Line") Response.Write ("Third ASP.NET Line")End Sub

    Inserting ASP.NET code Example Line1: First HTML Line Line2: Second HTML Line Line3: Third HTML Line

  • Message3.aspxhtml>Inserting ASP.NET code Example

    Line1: First HTML LineLine2: Second HTML LineLine3: Third HTML Line

    Sub Page_Load()Response.Write ("First ASP.NET Line")Response.Write ("Second ASP.NET Line")Response.Write ("Third ASP.NET Line") End Sub

  • Render or inline code block interweave1.aspx

    Interweaving ASP.NET code and HTML Example

    Line1: First HTML Line

    Line2: Second HTML Line

    Line3: Third HTML Line

    NOT RECOMMENDED.

  • Interweave2.aspx A Server controlscript language="VB" runat="server">Sub Page_Load() Message.Text="The ASP.NET line"End Sub

    Inserting ASP.NET code Example

    First HTML Line Second HTML Line

  • Web application project files

    AssemblyInfo.vbInfo about the compiled project file stored in /bin and named project.dllGlobal.asaxEvent handler commands visible to all web forms in a projectGlobal.asax.resxDefine application resources such as text strings, images. Can change without recompiling project.Global.asax.vbAsp.net code for application events eg session.startProject.slnStores links to all project filesProject.suoVS.NET IDE configuration info for the proj.Project.vbprojConfiguration and build settings for project files.

  • Web application project files cont.

    Project.vbproj.webinfoURL to project web serverProject.vsdiscoEnables search for web servicesStyles.cssProject style sheetWeb.configProject and folder configuration informationWebform.aspxWeb form .aspx file;HtmlWebform.aspx.resxResources in corresponding web formWebform.aspx.vbCode written for the form (code behind)Bin\project.dllCompiled project output file (assembly)Bin\project.pdbDebugging information used by developer

  • Viewing the Assembly Create a simple class, compile the class into an assembly, then view the class using the IL DisassemblerOpen Notepad and type the code shown:' hello.vb - displays hello world ' Created 06/01/2002Imports SystemPublic Module HelloSub Main()Dim s1 As String = "1 - Hello World" Console.WriteLine(s1)End SubEnd Module' Run this at the command line' vbc hello.vb

  • Using the ILDASM to View the Assembly and Classes Using the ILDASM to view the assembly and classes

  • Examplesquickstart webformsIntro4 shows VIEWSTATEIntro6 shows a click eventIntro7 shows a usercontrol with a calanderIntro8 shows a db connectionIntro9 & 10 show asp.net templatesIntro11shows validation controlsIntro13 shows code behind pagesServer directives eg trace and debugtrace

  • The lab environment.Each machine is set up to be an IIS server http://localhost:1900/..You create your web projects with Visual Studio.Net. VS.NET will create a subdirectory in c:/inetpub/wwwroot for your project. You must copy this subdirectory when moving to another machine or home.URL http://localhost:1900/MyfirstApp/homepage.aspxAlternative to VS.Net is webmatrixSome samples on another machine http://interdev.csse.monash.edu.au/cse2030/ Interdev is not accessible outside the Monash network.

  • ASP.NET Vs PHP