What Is ASP.NET?


Have you ever wondered how dynamic websites like Amazon.com work behind the scenes? As a shopper at Amazon.com, you are shown a particular web page, but the web page's content is dynamic, based on your preferences and actions. For example, if you have an account with Amazon.com, when you visit Amazon.com's home page, your name is shown at the top, and a list of personal recommendations is presented further down the page. When you type a book's title into the search text box, a list of matching books appears. When you click on a particular book's title, you are shown the book's details along with comments from other users and an overall rating. When you add the book to your shopping cart and check out, you are prompted for a credit card number, which is then billed.

Web pages in websites whose content is determined dynamically based on user input or other information are called dynamic web pages. For example, any website's search engine page is an example of a dynamic web page because the content of the search page is based on the search criteria the user entered and the documents on the web server. Another example is Amazon.com's personal recommendations. The books and products that Amazon.com suggests when you view the page are different from the books and products suggested when someone else views these pages. Specifically, the recommendations at Amazon.com are generated by products you have viewed as well as previous purchases you have made.

The opposite of a dynamic web page is a static web page. Static web pages contain content that does not change. HTML pages, for example, are static web pages. That is, an HTML page on a website with the following HTML markup is considered static:

<html> <body>   <b>Hello, World!</b> </body> </html> 


Such a page is considered a static web page because regardless of who views the page or what external factors there might be, the output will always be the same: the text "Hello, World!" in a bold font. The only time the content of a static web page changes is when someone edits the page and saves over the old version.

By the Way

Virtually all websites today contain a mix of static and dynamic web pages. Rarely will you find a website that has just static web pages because they are so limited in their functionality.


By learning ASP.NET, you will be learning how to create websites that contain dynamic web pages. It is important to understand the differences between how a website serves static web pages versus dynamic web pages.

By the Way: Competing Web Programming Technologies

ASP.NET is only one of many technologies that can be employed to generate dynamic web pages. ASP.NET is the successor to Active Server Pages (ASP), which was Microsoft's earlier dynamic web page creation technology. Other technologies include PHP, JSP, and ColdFusion.

Personally, I find ASP.NET to be the easiest and most powerful technology of the bunch, which is why I'm writing a book about ASP.NET instead of one of these other technologies. ASP.NET is head and shoulders above ASP. If you've created ASP scripts in the past, you'll no doubt find that you can do the same things you did in ASP by using ASP.NET but in a fraction of the time. Similarly, version 2.0 of ASP.NET provides numerous enhancements over version 1.0, including a vastly improved editorVisual Web Developerwhich is included on this book's accompanying CD.


Did you Know?

If you have experience developing web applications with other web programming technologies, such as ASP, PHP, or JSP, you may already be well versed in the material covered in the next two sections. If this is the case, feel free to skip to the "Installing the ASP.NET Engine, Editor, and Database System" section.


Serving Static Web Pages

If you've developed websites before, you likely know that a website requires a web server.

A web server is a software application that continually waits for incoming web requests, which are requests for a particular URL (see Figure 1.1). The web server examines the requested URL, locates the appropriate file, and then sends this file back to the client that made the web request.

Figure 1.1. The web server handles incoming web requests.


For example, when you visit Amazon.com, your browser makes a web request to Amazon.com's web server for a particular URL, say /books/index.html. Amazon.com's web server translates this requested URL into an actual file residing on the same computer where the web server resides. The web server returns the contents of the file, which is then rendered by your browser.

This web server model is adequate for serving static pages, whose contents do not change. However, such a simple model is insufficient for serving dynamic pages because the web server merely returns the contents of the requested URL to the browser that initiated the request. That is, the contents of the requested URL are not modified in any way by the web server based on external inputs.

Serving Dynamic Web Pages

With static web pages, the contents of the web page are just HTML elements that describe how the page should be rendered on a user's web browser. Therefore, when a static web page is requested, the web server can simply send the web page's content, without modification, to the requesting browser.

This simple model won't work for dynamic web pages, where the content of the web page can depend on various factors on a per-visitor basis. To accommodate dynamic content, dynamic web pages contain source code that is executed when the page is requested (see Figure 1.2). When the code is executed, it produces HTML markup as its result, which is then sent back to the visitor's browser.

Figure 1.2. The content of a dynamic web page is created by executing the dynamic web page's source code.


This model allows for dynamic content because the content for a dynamic web page isn't actually created until the web page is requested. For example, imagine that we wanted to create a web page that displays the current date and time. If we wanted to do this using a static web page, someone would need to edit the web page every second, continually updating the previous time on the page to the current time. Clearly, this isn't feasible.

With a dynamic web page, source code can retrieve and display the current date and time. Say that one particular user visits this page on February 4, 2006, at 4:15:03 P.M. When the web request arrives at this time, the dynamic web page's code is executed, which obtains the current date and time and returns it to the requesting web browser. The visitor will see, displayed in the browser, the date and time: February 4, 2006, 4:15:03 P.M. If another visitor requests this page 7 seconds later, the dynamic web page's code will be executed, which will obtain the current date and time (February 4, 2006, 4:15:10 P.M.) and will return it to the requesting web browser, where it will be displayed.

Figure 1.2 is, in actuality, a slightly oversimplified model. Commonly, the web server and the execution of the dynamic web page source code are decoupled. That is, when a web request arrives, the web server determines whether the requested page is a static web page or dynamic web page. If the web page is static, the web page's contents are sent directly back to the browser that initiated the request (as shown in Figure 1.1). If, however, the requested web page is dynamicsay an ASP.NET web pagethe web server hands off responsibility of executing the page to the ASP.NET engine (see Figure 1.3).

Figure 1.3. Execution of an ASP.NET web page is handled by the ASP.NET engine.


The web server can determine if the requested page is a dynamic or static web page by the requested file's extension. If the extension is .aspx, then the web server knows the requested page is an ASP.NET web page and, therefore, hands off the request to the ASP.NET engine.

By the Way

The ASP.NET engine is a piece of software that knows how to execute ASP.NET web pages. Other web programming technologies, such as ASP, PHP, and JSP, have their own engines, which know how to execute ASP, PHP, and JSP pages.


When the ASP.NET engine executes an ASP.NET page, the engine generates the web page's resulting HTML output. This HTML output is then returned to the web server, which then returns the HTML to the browser that initiated the web request.

Hosting ASP.NET Web Pages

After we've created ASP.NET web pages, to be able to view them, we need to request the ASP.NET page through a web browser. The browser then sends a request to the web server, which dispatches the request to the ASP.NET engine. The engine processes the page and returns the resulting HTML markup to the browser. When you're developing ASP.NET websites, the ASP.NET web pages you create will be saved on your personal computer. For you to be able to test these pages, then, your computer must have a web server installed.

Fortunately, you do not need to concern yourself with installing a web server on your computer. Visual Web Developer, the editor we'll be using throughout this book to create our ASP.NET websites, includes a lightweight web server designed for testing ASP.NET pages locally. As we will see in later hours, when testing an ASP.NET page, Visual Web Developer starts its ASP.NET Development Web Server and launches a browser that issues a request of the form: http://localhost:portNumber/ASP.NET_Page.aspx.

The http://localhost portion of the request tells the browser to send the request to your personal computer's web server, as opposed to some other web server on the Internet. The portNumber specifies a particular port through which the request is made. All web servers listen for incoming requests on a particular port. When the ASP.NET Development Web Server is started, it chooses an open port, which is reflected in the portNumber portion of the URL. Finally, the ASP.NET_Page.aspx portion is the filename of the ASP.NET page being tested.

Hosting ASP.NET pages locally through the ASP.NET Development Web Server has a number of advantages:

  • Testing can be done while offline. Because the request from your browser is being directed to your own personal computer, you don't need to be connected to the Internet to test your ASP.NET pages.

  • It's fast. Local requests are, naturally, much quicker than requests that must travel over the Internet.

  • Advanced debugging features are available. By developing locally, you can use advanced debugging techniques, such as stepping through running code line-by-line.

  • It's secure. The ASP.NET Development Web Server allows only local connections. With this lightweight web server, you don't need to worry about hackers gaining access to your system through an open website.

The main disadvantage of hosting ASP.NET pages locally is that they can be viewed only from your own computer. That is, a visitor on another computer cannot enter some URL into his browser's Address bar that will visit the ASP.NET website you've created on your local computer. If you want to create an ASP.NET website that can be visited by anyone with an Internet connection, you should consider using a web-hosting company.

A web-hosting company has a number of Internet-accessible computers for individuals or companies to place their websites. These computers contain web servers that are accessible from any other computer on the Internet. When setting up an account, you can ask the company to register a domain name for you. A domain name is the text that a person would enter into the web browser to visit your website. (For example, the domain name of Microsoft's site is microsoft.com. For my personal website, I might choose scottmitchellinfo.com.)

Did you Know?

Of course, you can only choose a domain name that has not already been registered by somebody else. To determine whether your desired domain name is still available, visit http://www.netsol.com, where you can enter a domain name to check on its availability.


The benefits of using a web-hosting company to host your site include

  • A publicly available website With a web-hosting company, any visitor who has an Internet connection can visit your website!

  • Use of a domain name You can register a domain name and have it point to your website so that visitors can reach your website through a name like www.mysite.com.

  • Ability to focus 100% on building your website Installing a web server, applying the latest security patches, properly configuring domain names, and so forth can be tricky tasks. By using a web-hosting company, you are paying for this service, which allows you to concentrate on building your website.

By the Way

You can choose from literally thousands of web-hosting companies, ranging dramatically in price, performance, features, support, and other qualities. A great place to start shopping for a web-hosting company is at a website like http://www.tophosts.com or http://www.hostindex.com. These websites catalog the thousands of web-hosting companies and allow you to search through their database looking for companies that match your price range, feature needs, and so forth.

When you choose a web-hosting company that you'd like to do business with, be sure to contact the company and make certain it supports ASP.NET development.


After your web-hosting account is set up, you can move web pages to the computer where your account is hosted. Then you, or anyone else on the Internet, can visit these pages. If you upload a web page named index.htm and your domain name was bobshomepage.org, anyone could view the index.htm page by typing http://www.bobshomepage.org/index.htm into the browser's Address bar.

Getting Started with a Web-Hosting Company

Before you can create an account with a web-hosting company, you need to find a company that supports ASP.NET version 2.0. The easiest way to find such a company, in my opinion, is to check sites like TopHosts.com and HostIndex.com, which list thousands of web-hosting companies. You can search these sites' databases for web-hosting companies that meet certain criteria, such as cost per month, geographical location, web server platforms used, and other criteria.

Costs for web-hosting companies can range from a few dollars per month to hundreds or thousands of dollars per month, based on the features provided. Additionally, most web-hosting companies have a setup fee in the $25 to $100 range. On top of the web-hosting costs, you will probably want to register a domain name, which typically costs between $10 and $35 per year, depending on the domain name registrar used.

After you have picked out a web-hosting company and have double-checked that it supports ASP.NET development, contact the company's sales staff to create an account.

Develop Locally, Deploy to a Web Host

Because there are many advantages to hosting a site both locally and with a web-hosting company, often the best choice is to do both! I encourage you to develop, test, and debug your ASP.NET websites locally, through Visual Web Developer's built-in web server. After you have completed your site and are ready for visitors, then procure an account with a web-hosting company and deploy your site. This approach allows for the best of both worldsan ideal development environment with the end result of a publicly accessible website!

Can I Host a Website from My Personal Computer?

Readers who have always-on broadband connections, such as through a cable modem or DSL, and a static IP address may be able to host a website from their personal computers. For more information on this option, contact your broadband provider.

If you want a public website, I personally recommend that you go with a web-hosting company. Setting up your computer to host a public website can be a difficult process and, if not done correctly, can leave your computer open to a number of security threats. For example, in July 2001 an Internet worm named Code Red spread quickly across the Internet, infecting Microsoft web servers. (A worm is a program that replicates and distributes itself over a computer network.) Specifically, the worm defaced web pages by adding the following text: "HELLO! Welcome to http://www.worm.com! Hacked By Chinese!" (For more information on the Code Red worm, see http://www.cert.org/advisories/CA-2001-19.html.) By setting up a public web server on your personal computer, you open yourself up to this sort of attack.

You can neutralize such threats by keeping abreast of the latest security patches from Microsoft, along with the know-how on how to best secure systems. Chances are, the professionals at the web-hosting company have more experience setting up, administering, and securing web servers than you and therefore likely provide a better line of defense.





Sams Teach Yourself ASP. NET 2.0 in 24 Hours, Complete Starter Kit
Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
ISBN: 0672327384
EAN: 2147483647
Year: 2004
Pages: 233

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