C# Unit5 Notes

6
25 WEB DEVELOPMENT AND ASP.NET(UNIT - V) Web applications and web servers A web application can be understood as a collection of files (*.htm, *.asp, *.aspx, image files, etc.) and related components (such as a .NET code library) stored within a particular set of directories on a given web server. 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 Server (IIS) is Microsoft’s enterprise-level web server product, and it has necessary support for classic ASP as well as ASP.NET web applications. Working with IIS Virtual Directories 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 local 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 site’s IP address has been registered with the world at large). Under the hood, the virtual directory maps to a physical root directory such as C:\inetpub\wwwroot\AspNetCarsSite, which contains the content of the web application. HTML form Development The real action of an *.htm file occurs within the scope of the <form> elements. An HTML form is simply a named group of related UI elements used to gather user input, which is then transmitted to the web application via HTTP Typically, the opening <form> tag supplies an action attribute that specifies the URL to which to submit the form data, as well as the method of transmitting that data itself (POST or GET). <html> <head> <title>My Site</title> </head> <body> <form action=”success.html” method=”POST”> <!-- Insert web content here -> </form> </body> </html>

description

Web applications and web servers, HTML form Development, GET and POST, ASP.NET application, ASP.NET namespaces, creating sample C# web Applications, architecture, Debugging and Tracing of ASP.NET, Introduction to web Form controls. Building Web Services- web service namespaces, building simple web

Transcript of C# Unit5 Notes

Page 1: C# Unit5 Notes

25

WEB DEVELOPMENT AND ASP.NET(UNIT - V)

Web applications and web servers A web application can be understood as a collection of files (*.htm, *.asp, *.aspx, image

files, etc.) and related components (such as a .NET code library) stored within a particular set of directories on a given web server.

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 Server (IIS) is Microsoft’s enterprise-level web server product, and it has necessary support for classic ASP as well as ASP.NET web applications.

Working with IIS Virtual Directories 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 local 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 site’s IP address has been registered with the world at large). Under the hood, the virtual directory maps to a physical root directory such as C:\inetpub\wwwroot\AspNetCarsSite, which contains the content of the web application.

HTML form Development The real action of an *.htm file occurs within the scope of the <form> elements.

An HTML form is simply a named group of related UI elements used to gather user input, which is then transmitted to the web application via HTTP

Typically, the opening <form> tag supplies an action attribute that specifies the URL to which to submit the form data, as well as the method of transmitting that data itself (POST or GET). <html> <head> <title>My Site</title> </head> <body> <form action=”success.html” method=”POST”> <!-- Insert web content here -> </form> </body> </html>

Page 2: C# Unit5 Notes

26

GET and POST (Submitting the Form Data) Used to submit form data to the web server for processing. <form name="defaultPage" id="defaultPage" action="ClassicAspPage.asp" method = "GET"> ... </form> GET: When you specify method = "GET" as the mode of transmission, the form data is appended to the query string as a set of name/value pairs separated by ampersands: http://localhost/Cars/ClassicAspPage.asp?txtUserName=Andrew&txtPassword=abcd123 POST: The other method of transmitting form data to the web server is to specify method = "POST". In this case, the form data is not appended to the query string, but instead is written to a separate line within the HTTP header. Using POST, the form data is not directly visible to the outside world. More important, POST data does not have a character-length limitation (many browsers have a limit for GET queries). ASP.NET application Below is the simple asp.net application using VBScript. Index.asp <html> <body> <form action=”process.asp” method=”GET” > Username: <input type=”text” name=”txtUserName” /> Password: <input type=”text” name=”txtPassword” /> <input type=”submit” name=”btnSubmit” /> </form> </body> </html>

process.asp <%@ language="VBScript" %> <html> <head> <title>Demo </title> </head> <body> <h1> Here is what you sent me:</h1> <%= Dim name = Request.QueryString("txtUserName ") <%= Dim pwd = Request.QueryString("txtPassword") %> User Name: <%=Response.Write(name) %> <br> Password: <%=Response.Write(pwd) %> </body> </html>

Page 3: C# Unit5 Notes

27

ASP.NET namespaces As of .NET 2.0, there are no fewer than 34 web-centric namespaces in the base class libraries. These namespaces can be grouped into four major categories:

1. Core functionality (e.g., types that allow you to interact with the HTTP request and response) 2. Web Form and HTML controls 3. Mobile web development 4. XML web services

Below table describes several of the core ASP.NET 2.0 namespaces.

Creating sample C# web Applications <% HelloWorldLabel.Text = "Hello, world!"; %> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>MyPage</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label runat="server" id="HelloWorldLabel"></asp:Label> </div> </form> </body> </html>

Page 4: C# Unit5 Notes

28

ASP.NET Website Directory Structure

Life Cycle of an ASP.NET Web Page

Page 5: C# Unit5 Notes

29

Introduction to web Form controls Web Forms are compiled and executed on the server, which generates the HTML that

displays the web pages.

Web Forms comes with hundreds of different web controls and web components to build user-driven web sites with data access.

The types in System.Web.UI.WebControls can be broken down into several broad categories:

Simple controls - The simple controls are so named because they are ASP.NET web controls that map to

standard HTML widgets (buttons, lists, hyperlinks, image holders, tables, etc.).

Rich controls - Rich controls are those for which there is no direct HTML equivalent (such as the

Calendar, TreeView, Wizard, etc.)

Data-centric controls - Data-centric controls are widgets that are typically populated via a given data

connection. (eg, GridView)

Input validation controls - Validation controls are server-side widgets that automatically emit client-side

JavaScript, for the purpose of form field validation

Login controls - These UI elements completely encapsulate the details of logging into a site, providing

password-retrieval services and managing user roles

Building Web Services The term "web service" refers to a form of a component that can be used remotely Microsoft offers two types of web services in their .NET framework, XML web services and .NET remoting. Web services are invoked remotely using SOAP(Simple Object Access Protocol) or HTTP-GET and HTTP-POST protocols . The file extension for a web service is .asmx. Benefits of XML Web Services: Language and platform independence: XML web services provide a way for unrelated platforms, operating systems, and programming languages to exchange information in harmony. Automatic upgrade: Unlike components, if a web service requires an update, that update is propagated to all applications consuming that web service immediately The following code shows the most basic web service: HelloWorld.asmx <%@ WebService Language="C#" class="HelloWorld"%> using System.Web.Services; public class HelloWorld : WebService{ // HelloWorld class inherits from the WebService base class [WebMethod] // indicates to IIS and the .NET compiler that the following method is to be exposed and web callable. public string HelloWorldMethod() { return "Hello World";

} }

Page 6: C# Unit5 Notes

30

Web Service Namespace The base class libraries define a number of namespaces that allow you to interact with each web service technology