Session 01
Session 01
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
Ver. 1.0
Slide 2 of 39
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
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).
Ver. 1.0
Slide 4 of 39
Ver. 1.0
Slide 5 of 39
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
Ver. 1.0
Slide 7 of 39
Ver. 1.0
Slide 8 of 39
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
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
The following figure depicts how a Web server processes a request for an ASP.NET file.
Ver. 1.0
Slide 11 of 39
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
Ver. 1.0
Slide 13 of 39
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
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
Ver. 1.0
Slide 15 of 39
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
Ver. 1.0
Slide 17 of 39
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
Ver. 1.0
Slide 18 of 39
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
Ver. 1.0
Slide 20 of 39
Slide 21 of 39
Ver. 1.0
Slide 22 of 39
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
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
Ver. 1.0
Slide 25 of 39
Ver. 1.0
Slide 26 of 39
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.
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
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
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.
Ver. 1.0
Slide 29 of 39
Ver. 1.0
Slide 30 of 39
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
Ver. 1.0
Slide 32 of 39
Ver. 1.0
Slide 33 of 39
Ver. 1.0
Slide 34 of 39
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
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
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
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
Ver. 1.0
Slide 38 of 39
ASP.NET provides two models for managing the visual elements and code:
Single-file page model Code-behind page model
Ver. 1.0
Slide 39 of 39