15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1150 ❘ ChaPTer 40 cOre Asp.net<br />

asP.neT inTroduCTion<br />

ASP.<strong>NET</strong> works with Internet Information Services (IIS) to deliver content in response to HTTP<br />

requests. ASP.<strong>NET</strong> pages are found in .aspx files. Figure 40-1 illustrates the technology’s basic<br />

architecture.<br />

HTTP Request for .aspx<br />

Resource<br />

IIS Web Server<br />

ASP.<strong>NET</strong> Page in .aspx<br />

Resource<br />

Server Processing<br />

of .aspx Resource<br />

Database<br />

ASP.<strong>NET</strong> Generated<br />

Resource in HTTP Response<br />

Result of .aspx<br />

Processing<br />

Other Resources<br />

figure 40-1<br />

OS<br />

.<strong>NET</strong> Framework<br />

how asP.neT files are Processed<br />

During ASP.<strong>NET</strong> processing, you have access to all .<strong>NET</strong> classes, custom components created in <strong>C#</strong> or<br />

other languages, databases, <strong>and</strong> so on. In fact, you have as much power as you would have running a <strong>C#</strong><br />

application; using <strong>C#</strong> in ASP.<strong>NET</strong> is, in effect, running a <strong>C#</strong> application.<br />

An ASP.<strong>NET</strong> file can contain any of the following:<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

Processing instructions for the server<br />

Code in <strong>C#</strong>, Visual Basic .<strong>NET</strong>, JScript .<strong>NET</strong>, or any other language that the .<strong>NET</strong> Framework<br />

supports<br />

Content in whatever form is appropriate for the generated resource, such as HTML<br />

Client-side script code, such as JavaScript<br />

Embedded ASP.<strong>NET</strong> server controls<br />

So, in fact, you could have an ASP.<strong>NET</strong> file as simple as this:<br />

Hello!<br />

This would simply result in an HTML page being returned (as HTML is the default output of ASP.<strong>NET</strong><br />

pages) containing just this text.<br />

As you will see later in this chapter, it is also possible to split certain portions of the code into other files,<br />

which can provide a more logical structure.<br />

Web sites <strong>and</strong> Web applications<br />

In ASP.<strong>NET</strong> it is possible to create both “web sites” <strong>and</strong> “web applications”. These two terms both mean<br />

that you supply a collection of ASP.<strong>NET</strong>, <strong>C#</strong>, <strong>and</strong> other files, but the way that they are processed is subtly<br />

different.<br />

In a web site, any code that you supply is dynamically compiled as <strong>and</strong> when it is required. This generally<br />

means that code is compiled the first time that the site is accessed. The .cs files for a web site are stored on<br />

the web server, which means that you can make changes by uploading new versions of these files, which will<br />

trigger a recompile the next time the site is accessed.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!