Solution Architecture


Microsoft released a relatively simple Web run-time environment called Active Server Pages (ASP) as part of Internet Information Server (IIS), itself part of the Windows NT 4 Option Pack, in the fall of 1997. IIS served up Web pages requested by the user. ASP allowed programmers to write program logic that dynamically constructed the pages that IIS supplied by mixing static HTML and scripting code, as shown in Listing 3-1. When a client requested an ASP page, IIS would locate the page and activate the ASP processor. The ASP processor would read the page and copy its HTML elements verbatim to an output page. In this case, the style attribute sets the text color to blue. It would also interpret the scripting elements, located within the delimiters <% %>. This code would perform program logic that rendered HTML strings as its output, which the ASP processor would copy to the location on the output page where the scripting element appeared. The resulting page, assembled from the static HTML elements and HTML dynamically generated by the script, would be written back to the client, as shown in Figure 3-3. ASP was relatively easy to use for simple tasks, which is the hallmark of a good first release.

The original ASP was a Web server run-time environment that was easy to use for simple tasks.

Listing 3-1: Intermingling of code and HTML in ASP.

start example
<html style="color:#0000FF;"> The time is: <% =time %> on <% =date %> </html>
end example

click to expand
Figure 3-3: The Web page produced by ASP after processing the HTML/ code mixture in Listing 3-1.

As the Web spread and user demands increased, Web programmers required more sophistication from their Web run-time environment in two key areas: making it easier to program and making it run better. ASP.NET is a big improvement in both these areas. ASP.NET looks somewhat like the original ASP, and most code will port between the versions unchanged or very close to it. But internally ASP.NET has been completely redone to take advantage of the .NET Framework. You’ll find that it runs better, crashes less, and is easier to program. These are good things to have. I discuss all of these features in more depth later in this chapter.

ASP.NET is a complete rewrite of the original ASP, keeping the best concepts.

ASP’s mingling of HTML output elements and scripting code may look logical, but it’s the devil to program and maintain in any but the simplest cases. Because code and data could and did appear anywhere on the page, intelligent development environments such as Visual Basic couldn’t make sense of it, so no one ever wrote a development environment that could handle ASP well. This meant that ASP code was harder to write than other types of code, such as a Visual Basic user interface application using forms. I know it drove me bats.

ASP.NET separates the HTML output from the program logic using a feature called code-behind. Instead of mixing HTML and code, you write the code in a separate file to which your ASP page contains a reference. You’d be astounded how much easier your code is to understand when you remove the distraction of HTML output syntax. It’s like getting your three year old to shut up while you’re talking taxes on the phone with your accountant. Because of this separation, Microsoft was able to enhance the Visual Studio .NET programming and debugging environment so that you can use it while developing your Web applications.

ASP.NET disentangles your code from the HTML.

Input and output in original ASP could be tricky, as the HTML environment was imperfectly abstracted. By this I mean that the programmer often had to spend time grappling with some fairly grotty HTML language constructs instead of thinking about her program logic, which isn’t the best use of resources. For example, parsing data out of HTML forms required much more work than doing the same thing on a desktop app. Producing output required the programmer to assemble HTML output streams, which again isn’t where you want your programmers to be spending their time. In Listing 3-1, our programmer had to know the proper HTML syntax for turning the text color blue.

ASP.NET supports Web Forms, which is a Web page architecture that makes programming a Web page very similar to programming a desktop application form. You add controls to the page and write handlers for their events, just as you do when writing a desktop app in Visual Basic. The ease of use that made Visual Basic so popular is now available for constructing Web applications. Just before the first edition of this book went to press, I taught a class on the beta 1 release of ASP.NET to a seasoned bunch of ASP developers, and this is the feature that made them literally stand up and cheer.

As Visual Basic depended on Windows controls and third-party ActiveX controls, so does Web Forms depend on a new type of control, named ASP.NET Server Controls. For convenience, I refer to these as Web controls in this chapter. These are pieces of prefabricated logic dealing with input and output that a designer places on ASP.NET pages, just as he did with a Windows application form. The controls abstract away the details of dealing with HTML, just as Windows controls did for the Windows GDI. For example, you no longer have to remember the HTML syntax for setting the foreground and background color for a line of text. Instead, you’ll use a label control and write code that accesses the control’s properties, just as you did in any other programming language. Think of how easy controls make it for you to program a simple desktop app in Visual Basic. Web controls do the same thing for ASP.NET pages.

ASP.NET contains prefabricated controls that do for HTML pages what Windows controls did for
Windows applications.

Original ASP included very little support for security programming. Security in ASP.NET is much easier to write. If you’re running in a Windows- only environment, you can authenticate a user (verify that he really is who he says he is) automatically using Windows built-in authentication. For the majority of installations that are not Windows-only, ASP.NET contains prefabricated support for implementing your own authentication scheme. And it also contains prefabricated support for Microsoft’s Passport worldwide authentication initiative, if you decide to go that route.

ASP.NET contains much good prefabricated support for securing your applications.

Original ASP supported session state management with an easy-to-use API. Its main drawbacks were that the state management couldn’t expand to more than one machine and that it couldn’t survive a process restart. ASP.NET expands this support by adding features that allow it to do both automatically. You can set ASP.NET to automatically save and later restore session state either to a designated server machine or to Microsoft SQL Server.

ASP.NET contains new session state management features that work on larger-scale Web farms.

ASP.NET contains many useful new run-time features as well. Original ASP executed rather slowly because the scripting code on its pages was interpreted at run time. ASP.NET automatically compiles pages, either when a page is placed on the server or when it’s first requested, which makes it run much faster. Because it uses the .NET Framework’s just-in-time compilation, you don’t have to stop the server to replace a component or a page. It also supports recycling of processes. Instead of keeping a process running indefinitely, ASP.NET can be set to automatically shut down and restart its server process after a configurable time interval or number of hits. As garbage collection solves the problem of memory leaks within managed .NET code, this process recycling solves many of the problems caused by leaking unmanaged external resources. This solves most problems of memory leaks in user code. ASP.NET also has the potential of being easier to administer because all settings are stored in human-readable files in the ASP directory hierarchy itself.

ASP.NET contains many features, making it run better and making it easier to administer.




Introducing Microsoft. NET
Introducing Microsoft .NET (Pro-Developer)
ISBN: 0735619182
EAN: 2147483647
Year: 2003
Pages: 110

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