Beruflich Dokumente
Kultur Dokumente
1.Introduction To ASP.NET
quite adequate for creating static Web content that some call brochure ware.
Although somewhat bloated, the pages are faithful reproductions of the original document especially when viewed in Microsofts latest Internet Explorer browser.
Expression Web:
Expression Web took over from Microsoft FrontPage as the content editor for professional designers. Although some see Expression as an advanced word processor for HTML pages, its actually much more, thanks to many important
tools for Web designers. These tools include file management, link checking,
style editing, and drag-and-drop support for HTML and ASP.NET controls. Expression Web inherited the excellent split-view editor from FrontPage that lets you work in graphical and source code modes at the same time. The feature is so well done that Microsoft yanked the HTML editor from Visual Web Developer and substituted the superior Expression/FrontPage version.
Expression Blend:
Expression Blend is mainly for the ponytail set (artistic types who prefer Macs) to create vector-based, animated, and three-dimensional graphics much the way they do in Photoshop. Blend has a rich set of brushes, palettes, paint buckets, text, gradients, timelines, and event triggers for those with the skill to take advantage of them. The XML-based files that Blend generates work in Windows Presentation
on the Microsoft platform. Just as Word is part of the Office suite, VWD is
part of the bigger Visual Studio 2008 suite. Visual Studio includes Visual Basic .NET, Visual C#, and many other tools. Visual Studio comes in several versions to target teams of developers, database designers, testers, and system architects. As an integrated development environment (IDE), Visual Web Developer helps you assemble and build the key elements of a Web application, including Web pages, images, controls, databases, style sheets, and, of course, the
programming logic.
the fly using a server-side script using a small set of COM objects and a bit of elbow grease.
For example, you may have a server-side VBScript (or JavaScript) block that reads a table from a data source using classic ADO and returns the rows as a generic HTML table.
languages such as VBScript and JavaScript are interpreted, type less entities that do not
lend themselves to robust OO programming techniques.
Another problem with classic ASP is the fact that an *.asp page does not yield very
modularized code. Given that ASP is a blend of HTML and script in a single page, most
ASP web applications are a confused mix of two different programming techniques. While it is true that classic ASP allows you to partition reusable code into distinct include files, the underlying object model does not support true separation of concerns. In an ideal world, a web framework would allow the presentation logic (i.e., HTML tags) to exist independently from the business logic (i.e., functional code).
A final issue to consider here is the fact that classic ASP demands a good deal of
boilerplate, redundant script code that tends to repeat between projects. Almost all web applications need to validate user input, repopulate the state of HTML widgets before emitting the HTTP response, generate an HTML table of data, and so forth.
another developer.
Because there is no dependency between files, a single-file page is easier to rename. Managing files in a source code control system is slightly easier, as all the action is taking place in a single file.
The default approach taken by Visual Studio 2008 (when creating a new website solution)
is to make use of a technique known as code-behind, which allows you to separate your
programming code from your HTML presentation logic using two distinct files. This model works quite well when your pages contain a significant amount of code or when multiple developers are working on the same website. The code-behind model offers several benefits as well: Because code-behind pages offer a clean separation of HTML markup and code, it is possible
to have designers working on the markup while programmers author the C# code.
Code is not exposed to page designers or others who are working only with the page markup (as you might guess, HTML folks are not always interested in viewing reams of C# code). Code files can be used across multiple *.aspx files.
attribute in question.
Every *.aspx file must have at minimum a <%@Page%> directive that is used to define the managed language used within the page (via the language attribute). Also, the <%@Page%> directive may define the name of the related code-behind file (if any), enable tracing support, and so forth. documents some of the more interesting <%@Page%>-centric attributes.
In addition to the <%@Page%> directive, a given *.aspx file may specify various <%@Import%> directives to explicitly state the namespaces required by the current page and <%@Assembly%> directives to specify the external code libraries used by the site
Debugging and Tracing ASP.NET Pages By and large, when you are building ASP.NET web projects, you can use the same debugging techniques as you would with any other sort of Visual Studio 2008 project type. Thus, you can set breakpoints in your code-behind file (as well as embedded script blocks in an *.aspx file), start a debug session (via the F5 key, by default), and step through your code. On a related note, you are also able to enable tracing support for an *.aspx file by setting the Trace attribute to true within the <%@Page%> directive (it is also possible to enable tracing for your entire site by modifying the Web.config file): insert your own trace messages into the mix, you can use the Trace property of the System.Web. UI.Page type. Anytime you wish to log a custom message (from a script
At this point, the browser opens a socket connection (typically via port 80 for a nonsecure
connection) and sends the HTTP request for processing to the target site. The web server receives the incoming HTTP request and may choose to process out any clientsupplied input values (such as values within a text box, check box selections, etc.) in order to format a proper HTTP response. Web programmers may leverage any number of technologies (CGI, ASP, ASP.NET, JSP, etc.) to dynamically generate the content to be emitted into the HTTP response. At this point, the client-side browser renders the HTML sent from the web server.
Another aspect of web development that is markedly different from traditional desktop
programming is the fact that HTTP is essentially a stateless wire protocol. As soon as the web server emits a response to the client, everything about the previous interaction is forgotten. This is certainly not the case for a traditional desktop application, where the state of the executable is most often alive and kicking until the user shuts down the application in question.Given this point, as a web developer, it is up to you take specific steps to remember information (such as items in a shopping cart, credit card numbers,
home and work addresses, etc.) about the users who are currently logged on to your site.
ASP.NET provides numerous ways to handle state, many of which are commonplace to any web platform (session variables, cookies, and application variables) as well as some .NETparticular techniques such as the ASP.NET profile management API
operation.
A web server is a software product in charge of hosting your web applications, and it typically provides a number of related services such as integrated security, File Transfer Protocol (FTP) support, mail exchange services, and so forth. Internet Information Services
(IIS) is Microsofts enterprise-level web server product, and as you would guess, it has
intrinsic support for classic ASP as well as ASP.NET web applications.
When you build production-ready ASP.NET web applications, you will often need to interact with IIS. Be aware, however, that IIS is not automatically selected as an installation option when you install the Windows operating system (also be aware that not all versions of Windows can support IIS, such as Windows XP Home). Thus, depending on the configuration of your development machine, you may wish to install IIS before proceeding through this chapter. To do so, simply access the Add/Remove Program applet from the Control Panel folder and select Add/Remove Windows Components. Consult the Windows help system if you require further details. Assuming you have IIS properly installed on your workstation, you can interact with IIS from the Administrative Tools folder (located in the Control Panel folder) by doubleclicking the Internet Information Services applet. For the purposes of this chapter, you
A single IIS installation is able to host numerous web applications, each of which resides in
a virtual directory. Each virtual directory is mapped to a physical directory on the hard drive. Therefore, if you create a new virtual directory named CarsRUs, the outside world can navigate to this site using a URL such as http://www.CarsRUs.com (assuming your sites IP address has been registered with the world at large). Under the hood, this virtual directory maps to a physical root directory on the web server, such as C:\inetpub\wwwroot\AspNetCarsSite, which contains the content of the CarsRUs
web application. As you will see later in this chapter, when you create ASP.NET web
applications using Visual Studio 2008, you have the option of having the IDE generate a new virtual directory for the current website automatically. If required, you are certainly able to manually create a virtual directory by hand by right-clicking the Default Web Site node of IIS and selecting New Virtual Directory (or on Vista, simply Add Virtual Directory) from the context menu.
The ASP.NET Development Server Prior to .NET 2.0, ASP.NET developers were required to make use of IIS virtual directories during the development and testing of their web content. In many cases, this tight dependency on IIS made team development more complex than necessary (not to mention that many network administrators frowned upon installing IIS on every developers machine). Thankfully, we now have the option to use a lightweight web server
you will be presented with a message box that describes the valid command-line options. In a nutshell, you will need to specify an unused port (via the /port: option), the root directory of the web application (via the /path: option), and an optional virtual path using the /vpath: option (if you do not supply a /vpath: option, the default is simply /). Consider the following usage, which opens an arbitrary port to view content in the
development is one of the major reasons why many programmers dislike building webbased programs. While it is true that modern IDEs (including Visual Studio 2008) and web development platforms (such as ASP.NET) generate much of the HTML automatically, you will do well to have a working knowledge of HTML as you work with ASP.NET. While this section will most certainly not cover all aspects of HTML (by any means), lets check out some basics and build a simple web application using HTML, classic (COMbased) ASP, and IIS. This will serve as a road map for those of you coming to ASP.NET
HTML Document Structure <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> </head> <body> </body> </html>
First of all, notice that this HTML file opens with a DOCTYPE processing instruction. This
informs the IDE that the contained HTML tags should be validated against the XHTML standard. As suggested, traditional HTML was very loose in its syntax. For example, it was permissible to define an opening element (such as <br>, for a line break) that did not have a corresponding closing break (</br> in this case), was not case sensitive, and so forth. The XHTML standard is a W3C specification that adds some much-needed rigor to the HTML markup language.
PreInit: Inidicates the moment immediately before page has been loaded into memory.
Init: Indicates the moment page initializing. InitComplete: Indicates the page has been initialized. PreLoad: Indicates the moment immediately before a page is Loaded. Load: indicates while page Loading. LoadComplete: indicates the moment has been Loaded . PreRender: Indicated the moment immediate before page display in the browser.
PreRenderComplete: Indicates the moment directly before a page has been rendered in
the browser. Unload: Indicates the moment page has been closed. protected void Page_Load(object sender, EventArgs e) { Trace.Write("I am tracing this application"); } protected void page_PreInit(object sender, EventArgs e) { Response.Write("page_PreInit"+"</br>" ); }
process events (such as button click event).A post back is just that-a posting back to the
same page. protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == true) { Response.Write("Page Postback"); } else { Response.Write("Page not Postback"); } }
ASP.NET Folders:
App_Code: App_Data: App_Theme:
App_GlobalResources:
App_LocalResources: App_WebRefrences: App_Browsers: