Jump to content

ASP.NET: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Root4(one) (talk | contribs)
m →‎Development tools: even the express edition can multi-target.
Root4(one) (talk | contribs)
Line 150: Line 150:
*[[Visual Studio .NET]] (for ASP.NET 1.x)
*[[Visual Studio .NET]] (for ASP.NET 1.x)
*[[Visual Web Developer Express Edition|Visual Web Developer 2005 Express Edition]] (free) or [[Visual Studio 2005]] (for ASP.NET 2.0)
*[[Visual Web Developer Express Edition|Visual Web Developer 2005 Express Edition]] (free) or [[Visual Studio 2005]] (for ASP.NET 2.0)
*[[Visual Web Developer Express Edition|Visual Web Developer 2008 Express Edition]] (free) or [[Visual Studio 2008]] (for ASP.NET 2.0/3.5)[http://www.microsoft.com/express/support/faq/]
*[[Visual Web Developer Express Edition|Visual Web Developer 2008 Express Edition]] (free) or [[Visual Studio 2008]] (for ASP.NET 2.0/3.5)<ref>[http://www.microsoft.com/express/support/faq/ VS Express FAQ]</ref>


==Frameworks==
==Frameworks==

Revision as of 00:28, 14 April 2008

File:ASPNETlogo.gif
ASP.NET logo

ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language.

Characteristics

ASPX FILE format

ASPX is an html file format used to create Webform pages; in programming jargon, the ASPX file typically contains static HTML or XHTML markup, as well as markup defining Web Controls and Web User Controls where the developers place all the required static and dynamic content for the web page. Additionally, dynamic code which runs on the server can be placed in a page within a block <% -- dynamic code -- %> which is similar to other web development technologies such as PHP, JSP, and ASP, but this practice is generally frowned upon by Microsoft except for the purposes of data binding since it requires more calls when rendering the page.

It is recommended by Microsoft for dealing with dynamic program code to use the code-behind model, which places this code in a separate file or in a specially designated script tag. Code-behind files are typically named something to the effect of MyPage.aspx.cs or MyPage.aspx.vb based on the ASPX file name (this practice is automatic in Microsoft Visual Studio and other IDEs). When using this style of programming, the developer writes code to respond to different events, like the page being loaded, or a control being clicked, rather than a procedural walk through the document.

ASP.NET's code-behind model marks a departure from other web programming languages (including Classic ASP) in that it attempts to separate the design code from the programming code itself. In theory, this would allow a web designer, for example, to focus on the design markup with less potential for disturbing the programming code that drives it.

Sample ASPX page

Note that this sample uses code "inline", as opposed to code behind.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToLongDateString();
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Sample page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label runat="server" id="Label1" />
    </div>
    </form>

</body>
</html>

Headline text

Rendering technique

'ASP.NET' uses a visited composites rendering technique. During compilation the template (.aspx) file is compiled into initialization code which will build a control tree (the composite) representing the original (static) template. Literal text goes into instances of the Literal control class, server controls are represented by instances of a specific control class. The initialization code is combined with user-written code (usually by the assembly of multiple partial classes) and results in a class specific for the page. The page doubles as the root of the control tree.

Actual requests for the page are processed through a number of steps. First, during the initialization steps, an instance of the page class is created and the initialization code is executed. This produces the initial control tree which is now typically manipulated by the methods of the page in the following steps. As each node in the tree is a control represented as an instance of a class, the code may change the tree structure as well as manipulate the properties/methods of the individual nodes. Finally, during the rendering step a visitor is used to visit every node in the tree, asking each node to render itself using the methods of the visitor. The resulting HTML code is sent to the client.

After the request has been processed, the instance of the page class is discarded and with it the entire control tree.

Other files

Other file extensions associated with different versions of ASP.NET include:

Extension Required version Descripion
asax 1.0 Global.asax, used for application-level logic [1]
ascx 1.0 Web UserControls: custom controls to be placed onto web pages.
ashx 1.0 custom HTTP handlers.
asmx 1.0 web service pages.
axd 1.0 when enabled in web.config requesting trace.axd outputs application-level tracing. Also used for the special webresource axd handler which allows control/component developers to package a component/control complete with images, script, css etc. for deployment in a single file (an 'assembly')
browser 2.0 browser capabilities files stored in XML format; introduced in version 2.0. ASP.NET 2 includes many of these by default, to support common web browsers. These specify which browsers have which capabilities, so that ASP.NET 2 can automatically customize and optimize its output accordingly. Special .browser files are available for free download to handle, for instance, the W3C Validator, so that it properly shows standards-compliant pages as being standards-compliant. Replaces the harder-to-use BrowserCaps section that was in machine.config and could be overridden in web.config in ASP.NET 1.x.
config 1.0 web.config is the only file in a specific Web application to use this extension by default (machine.config similarly affects the entire Web server and all applications on it), however ASP.NET provides facilities to create and consume other config files. These are stored in XML format, so as to allow configuration changes to be made with simplicity.
cs/vb 1.0 Code files (cs indicates C#, vb indicates Visual Basic). Code behind files (see above) predominantly have the extension ".aspx.cs" or ".aspx.vb" for the two most common languages. Other code files (often containing common "library" classes) can also exist in the web folders with the cs/vb extension. In ASP.NET 2 these should be placed inside the App_Code folder where they are dynamically compiled and available to the whole application.
dbml 3.5 LINQ to SQL data classes file
master 2.0 Master Pages
resx 1.0 resource files for internationalization and localization. Resource files can be global (e.g. messages) or "local" which means specific for a single aspx or ascx file.
sitemap 2.0 sitemap configuration files
skin 2.0 theme skin files.
svc 3.0 Windows Communication Foundation service file

Directory structure

In general, the ASP.NET directory structure can be determined by the developer's preferences. Apart from a few reserved directory names, the site can span any number of directories. The structure is typically reflected directly in the urls. Although ASP.NET provides means for intercepting the request at any point during processing, the developer is not forced to funnel requests through a central application or front controller.

The special directory names (from ASP.NET 2.0 on) are [2]:

App_Browsers
holds site-specific browser definition files.
App_Code
This is the "raw code" directory. The ASP.NET server will automatically compile files (and subdirectories) in this folder into an assembly which is accessible in the code of every page of the site. App_Code will typically be used for data access abstraction code, model code and business code. Also any site-specific http handlers and modules and web service implementation go in this directory. As an alternative to using App_Code the developer may opt to provide a separate assembly with precompiled code.
App_Data
default directory for databases, such as Access mdb files and SQL Server mdf files. This directory is usually the only one with write access for the application.
App_LocalResources
Contains localized resource files for individual pages of the site. E.g. a file called CheckOut.aspx.fr-FR.resx holds localized resources for the french version of the CheckOut.aspx page. When the UI culture is set to french, ASP.NET will automatically find and use this file for localization.
App_GlobalResources
Holds resx files with localized resources available to every page of the site. This is where the ASP.NET developer will typically store localized messages etc. which are used on more than one page.
App_Themes
holds alternative themes of the site.
App_WebReferences
holds discovery files and WSDL files for references to web services to be consumed in the site.
Bin
Contains compiled code (.dll files) for controls, components, or other code that you want to reference in your application. Any classes represented by code in the Bin folder are automatically referenced in your application.

Performance

ASP.NET aims for performance benefits over other script-based technologies (including Classic ASP) by compiling the server-side code to one or more DLL files on the web server. This compilation happens automatically the first time a page is requested (which means the developer need not perform a separate compilation step for pages). This feature provides the ease of development offered by scripting languages with the performance benefits of a compiled binary. However, the compilation might cause a noticeable delay to the web user when the newly-edited page is first requested from the web server.

The ASPX and other resource files are placed in a virtual host on an Internet Information Services server (or other compatible ASP.NET servers; see Other Implementations, below). The first time a client requests a page, the .NET framework parses and compiles the file(s) into a .NET assembly and sends the response; subsequent requests are served from the DLL files. By default ASP.NET will compile the entire site in batches of 1000 files upon first request. If the compilation delay is causing problems, the batch size or the compilation strategy may be tweaked.

Developers can also choose to pre-compile their code before deployment, eliminating the need for just-in-time compilation in a production environment.

Extension

Microsoft has released some extension frameworks that plug into ASP.NET and extend its functionality. Some of them are:

ASP.NET AJAX
An extension with both client-side as well as server-side components for writing ASP.NET pages that incorporate AJAX functionality.
ASP.NET MVC Framework
An extension to author ASP.NET pages using the MVC architecture.

ASP.NET compared to ASP classic

ASP.NET attempts to simplify developers' transition from Windows application development to web development by offering the ability to build pages composed of controls similar to a Windows user interface. A web control, such as a button or label, functions in very much the same way as its Windows counterpart: code can assign its properties and respond to its events. Controls know how to render themselves: whereas Windows controls draw themselves to the screen, web controls produce segments of HTML and JavaScript which form part of the resulting page sent to the end-user's browser.

ASP.NET encourages the programmer to develop applications using an event-driven GUI paradigm (event-driven GUI model), rather than in conventional web-scripting environments like ASP and PHP. The framework attempts to combine existing technologies such as JavaScript with internal components like "ViewState" to bring persistent (inter-request) state to the inherently stateless web environment.

Other differences compared to ASP classic are:

  • Compiled code means applications run faster with more design-time errors trapped at the development stage.
  • Significantly improved run-time error handling, making use of exception handling using try-catch blocks.
  • Similar metaphors to Windows applications such as controls and events.
  • An extensive set of controls and class libraries allows the rapid building of applications, plus user-defined controls allow commonly used templates, such as menus. Layout of these controls on a page is easier because most of it can be done visually in most editors.
  • ASP.NET leverages the multi-language capabilities of the .NET CLR, allowing web pages to be coded in VB.NET, C#, J#, Delphi.NET, Chrome etc.
  • Ability to cache the whole page or just parts of it to improve performance.
  • Ability to use the code-behind development model to separate business logic from presentation.
  • If an ASP.NET application leaks memory, the ASP.NET runtime unloads the AppDomain hosting the erring application and reloads the application in a new AppDomain.
  • Session state in ASP.NET can be saved in a SQL Server database or in a separate process running on the same machine as the web server or on a different machine. That way session values are not lost when the web server is reset or the ASP.NET worker process is recycled.
  • Previous versions of ASP.NET (1.0 and 1.1) were criticized for their lack of standards compliance. The generated HTML and JavaScript sent to the client browser would not always validate against W3C/ECMA standards. In addition, the framework's browser detection feature sometimes incorrectly identified web browsers other than Microsoft's own Internet Explorer as "downlevel" and returned HTML/JavaScript to these clients with some of the features removed, or sometimes crippled or broken. However, in version 2.0, all controls generate valid HTML 4.0, XHTML 1.0 (the default) or XHTML 1.1 output, depending on the site configuration. Detection of standards-compliant web browsers is more robust and support for Cascading Style Sheets is more extensive.
  • Web Server Controls: these are controls introduced by ASP.net for providing the UI for the web form. These controls are state managed controls and are WYSIWYG (What You See Is What You Get) controls.

Criticisms of ASP.NET

On IIS 6.0 and lower, pages written using different versions of the ASP framework can't share Session State without the use of third-party libraries. This criticism does not apply to ASP.NET and ASP applications running side by side on IIS 7. With IIS 7, modules may be run in an integrated pipeline that allows modules written in any language to be executed for any request.[3] [citation needed]

ASP.NET 2.0 produces markup that passes W3C validation, but it is debatable as to whether this increases accessibility, one of the benefits of a semantic XHTML page + CSS representation. Several controls, such as the Login controls and the Wizard control, use HTML tables for layout by default. Microsoft has now gone some way to solve this problem by releasing the ASP.NET 2.0 CSS Control Adapters, a free add-on that produces compliant accessible XHTML+CSS markup. However, some controls still rely on JavaScript.

Development tools

Several available software packages exist for developing ASP.NET applications:

Frameworks

It is not essential to use the standard webforms development model when developing with ASP.NET. Noteworthy frameworks designed for the platform include:

History

Date Version Remarks New features
January 16, 2002 1.0 First version

released together with Visual Studio .NET

  • Object oriented web application development supporting Inheritance, Polymorphism and other standard OOP features
    • Developers are no longer forced to use Server.CreateObject(...), so early-binding and type safety are possible.
  • Based on Windows programming; the developer can make use of DLL class libraries and other features of the web server to build more robust applications that do more than simply rendering HTML ( i.e. exception handling )
April 24, 2003 1.1 released together with Windows Server 2003

released together with Visual Studio .NET 2003

  • Mobile controls
  • Automatic input validation
November 7, 2005 2.0

codename Whidbey
released together with Visual Studio 2005 and Visual Web Developer Express
and SQL Server 2005

  • New data controls (GridView, FormView, DetailsView)
  • New technique for declarative data access (SqlDataSource, ObjectDataSource, XmlDataSource controls)
  • Navigation controls
  • Master pages
  • Login controls
  • Themes
  • Skins
  • Web parts
  • Personalization services
  • Full pre-compilation
  • New localization technique
  • Support for 64-bit processors
  • Provider class model
November 6, 2006 3.0

previously known as WinFX
released as an add-on to Visual Studio 2005

November 19 2007 3.5

released together with Visual Studio 2008

  • New data controls (ListView, DataPager)
  • Integrated AJAX support
  • Improved support for nested master pages
  • Support for LINQ

See also

ASP.NET Extensions

Alternatives to .NET and IIS

  • Mono - An open source, cross platform implementation of CLR, including an alternative implementation of ASP.NET.
  • UltiDev Cassini Web Server - A free web server that can be redistributed with ASP.NET 1.1 and 2.0 applications.

References

Additional resources

  • Stephen Walther: ASP.NET 3.5 Unleashed, December 28 2007, Sams Publishing, ISBN 0-672-33011-3
  • Stephen Walther: Data Access in the ASP.NET 2.0 Framework (Video Training), September 26 2007, Sams Publishing, ISBN 0-672-32952-2
ASP.NET Resources
ASP.NET Team Member blogs