Chapter 2: Introducing ASP.NET Applications


This chapter provides a tour through ASP.NET application architecture and reviews the more interesting features of ASP.NET applications. The larger purpose of this chapter is to give all readers a common understanding of the important features and issues in ASP.NET and to lay the groundwork for the rest of the book. Advanced readers, fear not! This chapter does not regurgitate basic ASP.NET 101 by repeating what you may have read in half a dozen other books. Instead, this chapter digs deeper into selected topics ranging from configuring ASP.NET to using view state. It also tackles underserved topics, such as how to customize configuration settings and how to write your own HttpHandler classes for low-level processing of HTTP requests . Finally, the topics covered are pertinent to discussions throughout the book.

Overview of ASP.NET Applications

An ASP.NET application is a collection of files, handler classes, and executable code that reside in a common virtual directory on a Web server. Valid ASP.NET files include the following:

  • Web forms: A Web form ( *.aspx ) provides a programming model for building user interface pages for a Web application. You construct Web forms using standard Hypertext Markup Language (HTML) mixed with server-side HTML, Web, and custom user controls. Web forms provide code-behind files, which include programmatic access to a Page handler object. You can code behind the Page object's lifecycle events using any standard .NET-compliant language. The filename suffix of the code-behind file reflects the language the code is written in ”for example, *.aspx.vb for Visual Basic .NET (VB .NET) code or *.aspx.cs for C# code. In addition, ASP.NET continues to support the classic ASP usage of inline server-side code mixed with HTML. However, this approach is not recommended for ASP.NET applications because it does not cleanly separate client-side and server-side codebases.

  • Web services: These are components that can be invoked remotely by client applications or other Web services, using Extensible Markup Language (XML) over Hypertext Transfer Protocol (HTTP) formatted in Simple Object Access Protocol (SOAP) envelopes. Web services are based on industry-standard specifications and can be consumed by heterogeneous clients on different platforms. Web services consist of an *.asmx file containing basic directives, plus a code-behind file that contains the methods and logic for the Web service. Visual Studio .NET is a powerful tool for creating XML Web services because it handles complex compilation details for you.

  • User controls: You can save Web forms as reusable components called user controls , which resemble Web forms in almost every way except that the file type uses an .ascx extension. You can drop user controls onto Web forms much like you can a standard server control, or you can dynamically load them onto the Web form at runtime. User controls provide a sophisticated way to reuse code and allow shared code to be maintained in a single location. User controls are also useful for implementing fragment caching in a Web form.

  • Code modules: These are stand-alone code module files that contain application-scope functions; any Web form, or module, in the application can call them. You can partition a single code module into several classes within one or more namespaces. Additionally, you can compile the code modules directly into the application executable, or you can move them to separate projects and compile them as stand-alone .NET components. You can write code modules in any .NET-compliant language, including VB .NET and C#.

  • Client-side scripts: For all of the server-side power of ASP.NET, client-side scripting still plays an important role. ASP.NET makes it easy to delegate a control's client-side events to server-side functions. But sometimes it is most efficient to handle the event on the client, using JavaScript or a similar scripting language. ASP.NET allows you to add client-side scripts to a project. Visual Studio .NET provides limited IntelliSense for JavaScript, as well as the ability to debug client-side scripts.

  • Web.config: This XML-based file stores configuration settings for ASP.NET applications and is discussed in great detail later in this chapter.

  • Global.asax: This file is the successor to the global.asa file from classic ASP. It provides programmatic access to application and session lifecycle events.

Visual Studio .NET is an excellent development tool for constructing Web applications. The most convenient aspect of the ASP.NET project type is that a single project can include all of the disparate executable content you need, even if that content resides in separate projects. For example, let's say your Web application requires Web forms, a Web service, and a set of .NET components. You could add three independent projects to the solution file to accommodate each of the different project types. Alternatively, you could include all of the executable source files in one project. This step saves you time and makes it somewhat easier to work on several parts of the project simultaneously . However, keep in mind the tradeoff to this approach, which is that all of the content will be compiled into a single, large DLL assembly that resides in the application's \bin directory. For production purposes, you should compile the parts of the application into separate DLLs or assemblies so that you can load them independently or deploy them to separate servers. Of course, separate assemblies are also useful because other applications can use them.




Performance Tuning and Optimizing ASP. NET Applications
Performance Tuning and Optimizing ASP.NET Applications
ISBN: 1590590724
EAN: 2147483647
Year: 2005
Pages: 91

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net