Lecture #1 ASP.NET in .NET Framework

Introduction ASP stands for Active Server Pages, while .Net simply means it is part of Microsoft’s .Net Framework. Although it was developed by Microsoft, ASP.NET is an open source server-side Web application framework designed for Web development to produce dynamic Web pages. When an ASP.NET application runs, the server maintains information about the current application, such as session, the current HTTP request, the requested page, and so on. can thus use a combination of ASP.NET tools to build function-rich applications to interact with the users and the client browsers. The Request object, for example, contains a property named Browser that returns an object of type HttpBrowserCapabilities. This object also provides properties such as browser, version, major version, and minor version such that programmers can use to determine the client browser type. The following is a sample ASP.NET code that can display information about the client browser.

<%@ Page Language="VB" %>

The following is the # version

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

......

ASP.Net – Penn Wu, PhD. 1 It is necessary to note that the curriculum guide for this class recommends that the instructor use .Net as the primary language to write demo scripts for the rest of this course’s lectures. The instructor, however, will provide C# version of the sample code for those who are familiar with the C# language throughout this course. Students have the options to use either VB .Net or C# to write ASP.NET programs to fulfil all course requirements, including assignments, exams, all learning activities.

“Classic ASP” Prior to the integration with .NET Framework, ASP is Microsoft’s first server-side script script and engine for dynamically generated web pages and was initially released as an add-on to Internet HTML Information Services (IIS) via the Windows NT 4.0 Option Pack in 1996. Throughout this course, the instructor uses the term “class ASP” to describe the syntax to write ASP codes before the integration of ASP and the .NET Framework in January 2002. Microsoft used to define “classic ASP” as a development framework for building web pages and web sites with HTML and CSS (cascading style sheet). A “classic ASP” script usually:  uses HTML tags to define the page layout  uses CSS to set the appearance of the page content  uses server-side ASP code, surrounded by the delimiters <% and %>, to dynamic generate contents.

It is necessary to note that “classic ASP” is a server-side language that must run inside IIS (Internet Information Services) servers. ASP codes will not run in a Windows machine unless IIS server is present. Instructions about how to obtain a free version of IIS, known as IIS Express, are available in a later section and the learning activities. The following is a very simple “class ASP” file whose file name extension is “.asp” (e.g. “test.asp”). It is created using “Notepad” (notepad.exe) which is a very generic text-editor included in all versions of since Windows 1.0 in 1985. By the way, the instructor purposely uses VBScript to write the following “classic ASP” script for the sake of demonstration. The code will return the current date and time values. By the way, throughout this course, let the file extension be “.aspx” to comply with the new naming convention of ASP.NET. A later section will discuss the new naming convention.

The server's current time:
<% Response.Write(Now()) %>

Unlike an .exe application, an ASP file is just a text file. An ASP file can contain text, HTML, XML, and ASP scripts; however, only the ASP scripts are executed on the server. In the above example, classic ASP scripts are enclosed by a pair of “<%” and “%>”. The rest of generic HTML codes. When a browser requests an ASP file, IIS passes the request to the ASP engine on the server. The ASP engine reads the file, line by line, and executes the scripts in the file. Finally, the ASP file is returned to the client browser as plain HTML. The following is a sample HTML content the above “classic APS” code will generate for the IIS server to send to the client browser.

The server's current time:
1/3/2015 11:47:04 AM

ASP.Net – Penn Wu, PhD. 2

Server-side scripts can only be read, interpreted, and executed by web servers to produce output; therefore, programmers must upload ASP files to an IIS server before an execution request can be made. The client browser can request ASP script for execution; however, the client browser does not and cannot have access to view the server-side script. It is necessary to note that server scripts are executed on the server, only HTML outputs will be returned to the client browser. During the HTTP-based communication, a client browser can only see and read HTML tags, CSS, and the results of server-side script.

Request execution Upload ASP Of ASP scripts ASP scripts IIS Client Programmers Server Browser Return HTML outputs

The following is a simple “classic” ASP script and its client-side result. ASP server-side script can contain any expressions, statements, procedures, or operators. In this script, the instructor declares a variable named “msg” using the dim keyword. The instructor then assigns a string, "Welcome to ASP!", to the “msg” variable as value. The response.write() method is a generic ASP method that writes output to a client browser. The client browser only receives the output produce by the response.write() method.

Server-side script Client-side result

<% Welcome to ASP! dim msg

msg = "Welcome to ASP!" response.write(msg) %>

HTML is the de facto language for creating web pages. ASP codes are typically embedded in an HTML page, even if the file extension is .apsx or .asp. It is necessary to have a understanding of HTML elements. HTML uses angle brackets to indicate how your content should be rendered (or displayed) in the browser. The angle brackets are referred to as tags; a pair of tags holding some text is referred to as an element. The following is a very simple HTML code. The declaration is a statement that declares to the web browser about what version of HTML the page is written in. This course adopts HTML5.

Hello World!

I am learning ASP.NET.

ASP.Net – Penn Wu, PhD. 3 An HTML element must start with a greater than (<) followed by the name of element and ends with less than sign (>). The “” and “” tags make a pair that encloses all the HTML contents. The “” tag is said to be the opening tag and “” is the closing tag. The closing tag always requires a forward slash (/). The “” and “” tags define a section that contains all the contents of an HTML document, such as text, hyperlinks, images, tables, lists, etc. The

element, with an opening tag (

) and a closing tag (

), is used to signify a heading at level one. The

tag defines a paragraph. Basically ASP is a development framework for building dynamic web pages and web sites with HTML.

The following is a list HTML elements frequently used throughout this course. The table is provided by Imar Spaanjaars, the author of a good reference book: Beginning ASP.NET 3.5: In C# and VB (ISBN: 978-0-470-18759-3).

Tag Description Example Used to denote the start and end of the entire page. Used to denote a special section <head> of the page that contains data <head> <title>Welcome to my <title> about the page, including its site title. Page body goes Used to denote the start and end of the body of the page. here Used to link one web page to another. AT&T site Used to embed images in a page. Used to format text in a bold, This is bold text while italic, or underline font. this text is in italic

Used for input forms that allow