Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
131 views

Session 01

The document provides an overview of developing web applications using ASP.NET. It discusses the basics of web development including static and dynamic web pages. Server-side scripting is described as executing code on the web server to provide dynamic content based on backend databases. ASP.NET is introduced as a server-side technology that enables creating dynamic web applications with features like simplicity, security and scalability. The document outlines how to create ASP.NET applications using Visual Studio and the anatomy of an ASP.NET application including specialized directories, file types and configuration files.

Uploaded by

Prerana Tokas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPS, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

Session 01

The document provides an overview of developing web applications using ASP.NET. It discusses the basics of web development including static and dynamic web pages. Server-side scripting is described as executing code on the web server to provide dynamic content based on backend databases. ASP.NET is introduced as a server-side technology that enables creating dynamic web applications with features like simplicity, security and scalability. The document outlines how to create ASP.NET applications using Visual Studio and the anatomy of an ASP.NET application including specialized directories, file types and configuration files.

Uploaded by

Prerana Tokas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPS, PDF, TXT or read online on Scribd
You are on page 1/ 39

Developing Web Applications Using ASP.

NET
Rationale

With the increased use of the Internet and advances in information technology, application developers need to quickly create applications that are accessible over the Web or a corporate intranet. The applications should also be efficient and effective. ASP.NET provides developers with various time saving and code saving features. One of its key design goals is to make programming easier and quicker by reducing the amount of code. In addition, it contains several new server controls, which eliminate the need for writing voluminous code.

Ver. 1.0

Slide 1 of 39

Developing Web Applications Using ASP.NET


Objectives

In this session, you will learn to:


Identify the basics of Web development Explore ASP.NET Develop ASP.NET applications

Ver. 1.0

Slide 2 of 39

Developing Web Applications Using ASP.NET


Introducing Web Development

Web applications are programs that can be executed on a Web server and accessed from a Web browser. Web applications enable organizations to share and access information on the Internet and corporate intranets. A Web application consists of the following types of Web pages:
Static Web page Dynamic Web page

An application that consists of dynamic Web pages is a dynamic Web application. A Web application can be made dynamic by using server-side and client-side scripts.

Ver. 1.0

Slide 3 of 39

Developing Web Applications Using ASP.NET


Server-Side Scripting

Server-side scripting provides users with dynamic content that is based on the information stored at a remote location, such as a back-end database. Server-side scripting includes code written in server-side scripting languages, such as:
Active Server Pages (ASP). Java Server Pages (JSP).

A server-side script is executed on a Web server.

Ver. 1.0

Slide 4 of 39

Developing Web Applications Using ASP.NET


Server-Side Scripting (Contd.)

The following figure shows the working of server-side scripts.

Ver. 1.0

Slide 5 of 39

Developing Web Applications Using ASP.NET


Client-Side Scripting

Client-side scripting:
Enables you to develop Web pages that can dynamically respond to user input without having to interact with a Web server. Provides dynamic content. Helps reduce network traffic because it does not need to interact with a Web server to provide dynamic response to user input. Speeds up the response time of a Web application.

Scripting languages such as VBScript and JavaScript are used to write client-side scripts.

Ver. 1.0

Slide 6 of 39

Developing Web Applications Using ASP.NET


Client-Side Scripting (Contd.)

The following figure shows the working of client-side scripts.

Ver. 1.0

Slide 7 of 39

Developing Web Applications Using ASP.NET


Client-Side Scripting (Contd.)

Limitations of client-side scripting:


Browser support: Client-side scripting is not supported equally by all browsers and operating systems. Isolation: Client-side scripts cannot access server-side resources. Security: Client-side scripts are visible to the end users. Therefore, they can be tampered by malicious users. Thin clients: Web-enabled devices such as mobile phones, palmtop computers, and Personal Digital Assistants (PDAs) do not support client-side scripting such as JavaScript or VBScript.

Ver. 1.0

Slide 8 of 39

Developing Web Applications Using ASP.NET


Exploring ASP.NET

ASP.NET is a server-side technology that enables programmers to create dynamic Web applications. ASP.NET has a number of advanced features such as simplicity, security, and scalability that help you develop robust Web applications. The various advanced features of ASP.NET are based on the .NET Framework.

Ver. 1.0

Slide 9 of 39

Developing Web Applications Using ASP.NET


ASP.NET in the .NET Framework

The following figure displays the elements of an ASP.NET application and how the elements fit in the broader context of the .NET Framework.

Ver. 1.0

Slide 10 of 39

Developing Web Applications Using ASP.NET


Working of an ASP.NET Application

The following figure depicts how a Web server processes a request for an ASP.NET file.

Ver. 1.0

Slide 11 of 39

Developing Web Applications Using ASP.NET


Developing ASP.NET Applications

An ASP.NET application can be created by using any text editor. However, this is a very time-consuming process. In addition, this process increases the possibility of inducing errors that could otherwise be avoided by using a design tool. A design and productivity tool, such as Visual Studio, provides various features that enable the developers to quickly create robust ASP.NET applications.

Ver. 1.0

Slide 12 of 39

Developing Web Applications Using ASP.NET


Developing ASP.NET Applications (Contd.)

Some of the features of Visual Studio IDE are:


Integrated error checking The Web form designer An integrated Web server Developer productivity enhancements Complete extensibility

Ver. 1.0

Slide 13 of 39

Developing Web Applications Using ASP.NET


Website Types

You can use Visual Studio 2008 to create the following types of websites:
File-system websites Local Internet Information Services (IIS) websites Remote IIS websites FTP sites

Let us see how to create an ASP.NET website Let us see how to open an existing ASP.NET website

Ver. 1.0

Slide 14 of 39

Developing Web Applications Using ASP.NET


Anatomy of an ASP.NET Application

The following table lists some specialized directories that an ASP.NET application uses.
Directory Bin App_Code App_Browsers App_GlobalResources App_LocalResources App_WebReferences App_Data Description Stores all the compiled .NET components (DLLs) that an ASP. Web application uses. Stores source code files that are dynamically compiled to be used in the Web application. Stores browser definition files. Browser definition files are XML files that define a browser with its properties, capabilities, and features. Stores global resources that are accessible to every page in the Web application. Stores .resx files that are accessible to a specific page only. Stores references to Web services that are used by the Web application. Stores data such as database files and XML files that are used by the application.

App_Themes

Stores the themes that are used in the Web application.

Ver. 1.0

Slide 15 of 39

Developing Web Applications Using ASP.NET


Anatomy of an ASP.NET Application (Contd.)

The following table lists some important file types that an ASP.NET Web applications can include.
File Name Ends with .aspx Description These are ASP.NET Web pages that contain the user interface and, optionally, the underlying application code. Users request or navigate directly to one of these pages to start a Web application. These are ASP.NET user controls. These controls are similar to Web pages, except that the user cannot access these files directly. Instead, they must be hosted inside an ASP.NET Web page. User controls allow you to develop a small piece of user interface and reuse it in as many Web forms as you want without repeating code. These are ASP.NET Web services. Web services are collections of methods that can be called over the Internet. Web services work differently than Web pages. However, they still share the same application resources, configuration settings, and memory. This is the XML-based configuration file for ASP.NET applications. It includes settings for customizing features such as security, state management, and memory management. This is the global application file. You can use this file to define global variables (variables that can be accessed from any Web page in the Web application). These are code-behind files that contain C# code. These files allow you to separate the application logic from the user interface of a Web page. These are default HTTP handlers for all Web handlers that do not have a user interface and that include the @ WebHandler directive. Slide 16 of 39

Ends with .ascx

Ends with .asmx web.config

Global.asax Ends with .cs

Ends with .ashx


Ver. 1.0

Developing Web Applications Using ASP.NET


Anatomy of an ASP.NET Application (Contd.)

Configuration files used in ASP.NET Web applications:


ASP.NET uses a hierarchy of configuration files to keep application configuration settings separate from the application code. A configuration file is an XML file that contains configuration settings for an application and has a .config extension. Benefits of a configuration file:
It provides control and flexibility over the way you run applications. It eliminates the need to recompile the application every time a setting changes. It controls access to protected resources, and the location of remote applications and objects by defining configuration settings.

Ver. 1.0

Slide 17 of 39

Developing Web Applications Using ASP.NET


Anatomy of an ASP.NET Application (Contd.)

The following table lists the levels, the corresponding configuration files, and their description.
Level Server Settings File Name Machine.config Description Present at the root of the configuration hierarchy. It defines global configuration settings for all . Framework applications. Present in the same directory as machine.config. It defines configuration settings for all ASP. applications. Present in the root directory of each IIS website. It contains settings that are specific to the website. Present in the root directory of each application. It contains settings that are specific to the application. Present in a subfolder of the application root. It contains settings for specific section of a Web application. Present at the root of the configuration hierarchy. It defines global configuration settings for all . Framework applications.

Root Web Settings Website settings (optional) Application root Settings (optional) Application subfolder (optional) Server Settings

Web.config Web.config Web.config Web.config Machine.config

Ver. 1.0

Slide 18 of 39

Developing Web Applications Using ASP.NET


ASP.NET Web Page Code Model

A Web page is made up of the following two components:


The visual portion: It refers to the static HTML and ASP.NET server controls that define the layout of a Web page. The programming logic: It refers to the code that is required to interact with the Web page.

ASP.NET provides the following two models for managing the visual elements and code:
Single-file page model Code-behind page model

Ver. 1.0

Slide 19 of 39

Developing Web Applications Using ASP.NET


ASP.NET Web Page Code Model (Contd.)

The single-file page model:


In the single-file page model, HTML markup of the page and its programming code are in the same physical .aspx file. The programming code is contained in a <script> block that specifies the attribute runat=server. The single-file page model provides the following advantages:
In pages with less code, keeping the programming code and the HTML markup in a single file proves to be very convenient while studying the file. Pages written by using the single-file model are slightly easier to deploy or to send to another programmer because there is only one file. A single-file page is easier to rename because there is no dependency between files. Managing files in a source code control system is slightly easier because the page is self-contained in a single file.

Ver. 1.0

Slide 20 of 39

Developing Web Applications Using ASP.NET


ASP.NET Web Page Code Model (Contd.)

The code-behind page model:


In the code-behind page model, HTML markup is kept in one file with extension .aspx and the programming code in another file with extension .cs or .vb. The code file contains a partial class, which indicates that the class contains only some of the total code that makes up the full class for the page. The code-behind model provides the following advantages:
It allows a developer to separate the UI display from the UI processing, thereby enabling the programmer to reuse the programming logic. It enables a developer to quickly debug the code because the code is not clubbed with the UI. It enables developers to quickly create a Web application by separating the design and development functions.

Let us see how to add a new Web form to an ASP.NET website


Ver. 1.0

Slide 21 of 39

Developing Web Applications Using ASP.NET


The Page Class All Web forms are instances of the ASP.NET Page class, which is defined in the System.Web.UI namespace. The Page class inherits the TemplateControl class, which, in turn, inherits the Control class. ASP.NET uses an event-driven model of programming, which defines a sequence of events that are raised during the lifecycle of a Web page.

Ver. 1.0

Slide 22 of 39

Developing Web Applications Using ASP.NET


The Page Class (Contd.)

The following table lists some of the page events:


Event
Init

Description
It is the first event that occurs when the server executes an ASP.NET page. It occurs only once in the entire lifecycle of an ASP.NET page. It is fired after the Init event, when the page is requested for the first time and whenever the page is reloaded. This event can be used to initialize the variables and the state of the controls that are used in the page. It represents the last event that occurs in the lifecycle of an ASP.NET page. This event is used to perform final cleanup work, such as the closing of open database connections, discarding objects, or closing files.

Load

Unload

Ver. 1.0

Slide 23 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET

ASP.NET provides the following built-in objects:


Application Request Response Server Session HttpContext

The built-in objects are made available to the Page object, which is an instance of the System.Web.UI.Page class from which all ASP.NET pages are inherited.

Ver. 1.0

Slide 24 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.) The Application object:
Provides a reference to an object of the HttpApplicationState class. Is used to store information that is defined for the entire Web application. Has the following properties:
Count: It returns the number of objects in the HttpApplicationState collection. Item: It provides access to an object in the HttpApplicationState collection.

Provides the following methods:


public void Lock(): It blocks the access to an Application variable or object. public void UnLock(): It releases the lock procured on an Application variable or object.

Ver. 1.0

Slide 25 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.) The Request object:
Provides a reference to an object of the HttpRequest class. Enables ASP.NET applications to access information sent by the client during a Web request. Provides the following method:
byte[] BinaryRead(int): Helps retrieve the data sent to the server from the client as part of a post request and stores it in an array.

Ver. 1.0

Slide 26 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.)

The following table describes some of the properties of the Request object.
Property ApplicationPath Url Description Returns the application root path of ASP.NET on the server. This is a read-only property. Returns a object, which will contain the complete address of the requested page. This is a read-only property. Returns the IP host address of the requesting client. Returns a sorted string array containing the language preferences of the client. Returns the HttpBrowserCapabilities object, which contains information about the browser capability of the client.

UserHostAddress UserLanguage Browser

Cookies
QueryString

Returns the HttpCookieCollection object, which provides access to the cookie variables of the client.
Provides access to the parameters passed from the client to the server along with a request.

Ver. 1.0

Slide 27 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.) The Response object:
Provides a reference to an object of the HttpResponse class. Enables ASP.NET applications to send information to the client.

The following table describes some of the properties of the Response object.
Property Buffer Cache ContentType Cookies Description Sets the buffer feature of the Response object. Provides access to the caching policy, such as the expiration time and privacy settings of the Web page. Sets or gets the type of data that is sent to the client through the Response object. Sets a cookie to the client browser.

IsClientConnect Returns a Boolean value indicating whether the client is ed connected or disconnected.

Ver. 1.0

Slide 28 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.)

The following table describes some of the methods of the Response object.
Method public void Clear() public void Close() public void End() Description Clears the content in the buffer of the Response object. Closes the connection to the client. Sends the buffered data to the client and closes the connection to the client. The End() method will raise an Application_EndRequest event. Sends the data in the buffer to the client but does not close the connection to the client. Redirects the new URL specified in the string parameter to the client. Writes a string on the form. It is an overloaded method.

public void Flush() public void Redirect(string) public void Write(string)

Let us see how to display a message on a Web page

Ver. 1.0

Slide 29 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.) The Server object:
Provides a reference to an object of the HttpServerUtility class. Provides methods that can be used to access the methods and properties of the Web server. Has the following properties:
MachineName: It returns the name of the server machine. ScriptTimeout: It helps get and set the request timeout in seconds for the Web server.

Ver. 1.0

Slide 30 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.)

The following table describes some of the methods of the Server object.
Method public void ClearError() public object CreateObject(String) public Exception GetLastError() public string MapPath(string path) public void Transfer(string) Description Clears the last error that has occurred on the server. Creates the server instance of a COM object. Returns an Exception object, which represents the last error that occurred on the server. Returns the physical file path on the Web server that corresponds to the specified virtual path. Terminates the processing of the current page and loads the page specified in the string format.

Ver. 1.0

Slide 31 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.) The Session object:
Provides a reference to an object of the HttpSessionState class. Enables ASP.NET applications to keep the state of the application as modified or changed by a client. Provides access to the session wide cache, which can be used to store information pertaining to the client. Has the following properties:
Count: It returns the number of items in the session-state collection. SessionID: It returns the unique session ID assigned for a session. Timeout: It enables to get and set the period in minutes that is allowed between requests by the client before the session-state provider terminates the session.

Ver. 1.0

Slide 32 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.)

Provides the following methods:


public void Add(string name, object value): Adds a new item to the session-state collection. public void Clear(): Clears all the values stored in the session-state collection. public void Remove(string name): Deletes an item from the session-state collection.

Ver. 1.0

Slide 33 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.) A new HttpContext object is created for every request sent to an ASP.NET application. The object is created at the beginning of a request and destroyed when the request is completed. The HttpContext object holds current request-specific information such as Request, Response, Server, and Session.

Ver. 1.0

Slide 34 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.)

The following table describes some of the properties of the HttpContext object.
Property AllErrors ApplicationInstance Timestamp Users Description Gets an array of errors that are accumulated while processing an HTTP request. Gets or sets the HttpApplication object for the current HTTP request. Gets the initial timestamp of the current HTTP request. Gets or sets security information for the current HTTP request.

Ver. 1.0

Slide 35 of 39

Developing Web Applications Using ASP.NET


Intrinsic Objects of ASP.NET (Contd.)

The following table describes some of the methods of the HttpContext object.
Method public void AddError(Exception errorInfo) public void ClearError() public object GetConfig(string name) Description Adds an exception to the exception collection for the current HTTP request. Clears all errors for the current HTTP request. Returns requested configuration information for the current HTTP request.

Ver. 1.0

Slide 36 of 39

Developing Web Applications Using ASP.NET


Summary

In this session, you learned that:


Web pages can be of the following types:
Static Web page Dynamic Web page

Server-side scripting provides users with dynamic content that is based on the information stored at a remote location. Client-side scripting enables you to develop Web pages that can dynamically respond to user input without having to interact with a Web server. An ASP.NET application has the following elements:
Web Form pages Configuration files XML Web service files

Ver. 1.0

Slide 37 of 39

Developing Web Applications Using ASP.NET


Summary (Contd.)

ASP.NET has the following advanced features that help develop robust Web applications:
Compiled code Enriched tool support Power and flexibility Simplicity Manageability Scalability Security Extensibility

A Web form is made up of the following two components:


The visual portion The programming logic

Ver. 1.0

Slide 38 of 39

Developing Web Applications Using ASP.NET


Summary (Contd.)

ASP.NET provides two models for managing the visual elements and code:
Single-file page model Code-behind page model

ASP.NET provides the following built-in objects:


Application Request Response Server Session HttpContext

Ver. 1.0

Slide 39 of 39

You might also like