Master of Computer Application (MCA) – Semester 5 MC0081 –.

(DOT) Net Technologies (Book ID: B0974)

Assignment Set – 1

1. Describe the steps involved in creating classes and objects with the help of a program in C#. A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events. A class is like a blueprint. It defines the data and behavior of a type. If the class is not declared as static, client code can use it by creating objects or instances which are assigned to a variable. The variable remains in memory until all references to it go out of scope. At that time, the CLR marks it as eligible for garbage collection. If the class is declared as static, then only one copy exists in memory and client code can only access it through the class itself, not an instance variable. For more information, see Static Classes and Static Class Members (C# Programming Guide). Unlike structs, classes support inheritance, a fundamental characteristic of object-oriented programming. Declaring classes public class Customer { //Fields, properties, methods and events go here... } Creating object Customer object1 = new Customer(); Class Inheritance public class Manager : Employee { // Employee fields, properties, methods and events are inherited // new Manager fields, properties, methods and events go here... } EXAMPLE public class Person { // Field public string name; // Constructor Public Person () { name = "unknown"; } // Method

to create and initialize server controls in the control tree. Load: CreateChildControls( ) is called. You can modify the load phase by handling the Load event with the OnLoad method. Console. Send Postback Change Modifications: If there are any state changes between the current state and the previous state. Console. used to persist the state across round trips to the server. the data sent to the server in the posting is processed.WriteLine(person. This can be modified via the LoadViewState( ) method: This allows ASP. Handle Postback Events: The client-side event that caused the postback is handled. The input string from this hidden variable is parsed by the page framework.WriteLine(person. person. These events. Console. Web Form Life Cycle Every request for a page made from a web server causes a chain of events at the server. } } /* Output:unknownJohn Smith*/ 2. and the ViewState property is set.SetName("John Smith"). and the form controls show client-side The ViewState information comes from a hidden variable on the control.WriteLine("Press any key to exit. It is here that any settings needed for the duration of the incoming request are initialized. constitute the life cycle of the page and all its components. the page is unloaded.NET server: Initialize: Initialize is the first phase in the life cycle for any page or control. Process Post back Data: During this phase. that update is performed via the LoadPostData( ) method. If any of this data results in a requirement to update the ViewState. Load View State: The ViewState property of the control is populated.Net environment: a. the goal is to render appropriate HTML output back to the requesting browser. // Keep the console window 3 Console. . change events are raised via the RaisePostDataChangedEvent( ) method. Describe the following with respect to creating Web Forms in . each of which you can handle yourself or leave to default handling by the ASP. State is restored.public void SetName(string newName) { name = newName. The life cycle of a page is marked by the following which causes the server to load it.NET to manage the state of your control across page loads so that each control is not reset to its default state each time the page is posted. if necessary."). From one end of the life cycle to the other. When the request is complete. from beginning to end. The life cycle begins with a request for the page. } } class TestPerson{static void Main() { Person person = new Person().

Creating a Web Form Write programs with corresponding output screens to demonstrate the above concepts. You can override it using the Render method. To create the simple Web Form that will be used in the next example. if necessary. Dispose: This is the last phase of the life cycle.NET will display http://localhost/ as the default location. It gives you an opportunity to do any final cleanup and release references to any expensive resources. ProgrammingCSharpWeb. and type in its name. Visual Studio .NET Web Application as the project type. Now it is saved back to the hidden variable. You can modify it using the Dispose( ) method. b. to create and initialize server controls in the control tree. Save State: Near the beginning of the life cycle. Render: This is where the output to be sent back to the client browser is generated. as shown in Figure . persisting as a string object that will complete the round trip to the client. Select the Visual C# Projects folder (because C# is your language of choice). You can override this using the SaveViewState() method. It is essentially your last chance to modify the output prior to rendering using the OnPreRender( ) method.PreRender: This is the phase just before the output is rendered to the browser.NET and open a New Project named ProgrammingCSharpWeb. CreateChildControls( ) is called. such as database connections. start up Visual Studio . select ASP. the persisted view state was loaded from the hidden variable.

cs) file.aspx and view the code. HTML mode allows you to view and edit the HTML code directly.When you create a new Web Form application. The solution files and other Visual Studio-specific files are stored in <drive>\Documents and Settings\<user name>\My Documents\Visual Studio Projects (where <drive>andappear in the Solution Explorer.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.aspx and code-behind files that Visual Studio creates.cs. To see the code behind (.aspx. open HelloWeb. you must place the cursor within Visual Studio .NET Visual Studio places nearly all the files it creates for the project in a folder within your local machine's default web site – for example. c:\Inetpub\wwwroot\ProgrammingCSharpWeb. You can now tab back and forth between the form itself.Creating a project in the New Project window of Visual Studio . and then right-click its name in the Solution Explorer. and the C# code-behind file. Let's take a closer look at the .NET code: <%@ Page language="c#" Codebehind="HelloWeb. as shown in Example below: <%@ Page language="c#" Codebehind="HelloWeb.NET.NET will generate a bit of boilerplate code to get you started. which contains the following ASP.0 Transitional//EN" > <html> <head> <title>WebForm1</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.aspx to HelloWeb.aspx.aspx.cs. you can choose between Design mode and HTML mode by clicking the tabs at the bottom of the Editor window.cs" AutoEventWireup="false" Inherits="ProgrammingCSharpWeb. To do this.aspx. close WebForm1. right-click the form. Visual Studio . When viewing the form. Choose Rename and enter the name HelloWeb.aspx. WebForm1. and choose "View Code" in the pop-up"> </head> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> </form> </body> </html> What you see is typical boilerplate HTML except for the first line.cs" AutoEventWireup="false" Inherits="ProgrammingCSharpWeb.aspx. WebForm1. After you rename it. Start by renaming WebForm1.WebForm1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. WebForm1. Design mode lets you drag controls onto your form.WebForm1" %> .aspx.aspx.aspx. you will find that the code-behind file has been renamed as well to HelloWeb.

The Codebehind attribute designates that the filename of that page is HelloWeb.The language attribute indicates that the language used on the code-behind page is C#.NET A cookie is a small amount of data that is stored either in a text file on the client file system or inmemory in the client browser session. Having created an empty Web Form. Cookies in ASP. WebForm1 inherits from System.Page As the C# code makes clear. the first thing you might want to do is add some text to the page. The attribute runat="server" is the key to the serverside magic.Now. and the Inherits attribute indicates that this page derives from WebForm1.cs.cs. %> Run the page by pressing Ctrl-F5 (or save it and navigate to it in your browser). indicating that code falls between them (in this case. Adding the following line to the body segment of the HTML page will cause it to display a greeting and the current local time: Hello World! It is now <% = DateTime. Any tag that includes this attribute is considered a server-side control to be executed by the ASP.aspx. WebForm1 is a class declared in HelloWeb. and events common to all server-side pages.Write( ). C#).ToString( ) %> The <% and %> marks work just as they did in classic ASP. methods. you see that a form has been specified in the body of the page using the standard HTML form tag: <form id="Form1" method="post" runat="server"> Web Forms assumes that you need at least one form to manage the user interaction. .Net: a. and creates one when you open a project.UI. You should see the string printed to the browser.Web.Write(DateTime. By switching to HTML view. as in Figure Output generated by the HelloWorld.NET framework on the server. public class WebForm1 : System.aspx file 3. Cookies can be temporary (with specific expiration times and dates) or persistent.ToString( )).NET to display the value. It contains site-specific information that the server sends to the client along with page output. Describe the following with respect to State Management in ASP. you can add script and HTML directly to the file just as you could with classic ASP. Returning to the HTML view of HelloWeb. just like a call to Response. The = sign immediately following the opening tag causes ASP.Now.Page. You could just as easily write the line as: Hello World! It is now <% Response.UI.Web. which is the class that defines the properties.

Application state is stored in a key/value dictionary that is created during each request to a specific URL. If different users are using your application. 4. Instead. Once you add your application-specific information to session state.You can use cookies to store information about a particular client. application state is useful for storing information that needs to be maintained between server round trips and between requests for pages. the second user session will have a different session state from the first. The cookies are saved on the client device. session.Net: a. in a cookie. such as a user name or password. Depending on which options you specify. In addition. and when the browser requests a page.NET allows you to save values using application state — which is an instance of the HttpApplicationState class — for each active Web application. You can add your application-specific information to this structure to store it between page requests. The server can read the cookie and extract its value. session information can be stored in cookies. Note: The browser can only send the data back to the server that originally created the cookie. -specific data on the server for use across multiple browser or client-device requests within the same session. the server manages this object. each user session will have a different session state. Thus. the server manages it. A typical use is to store a token (perhaps encrypted) indicating that the user has already been authenticated in your application. if a user leaves your application and then returns later. b. on an out-ofprocess server. Once you add your application-specific information to application state. store a token in the cookie that identifies the user. However. Application State ASP. It is recommended that you do not store sensitive information. Session state is structured as a key/value dictionary for storing session-specific information that needs to be maintained between server round trips and between requests for pages. Application state is a global storage mechanism that is accessible from all pages in the Web application. ing these events. Writing and Testing a Web Service . Session State ASP. Describe the following with respect to Web Services in . and then use the token to look up the sensitive information on the server. c. except that it is scoped to the current browser session. You can use session state to accomplish the following tasks: -device requests and map them to an individual session instance on the server.NET allows you to save values by using session state — which is an instance of the HttpSessionState class — for each active Web-application session. Session state is similar to application state. or on a computer running Microsoft SQL Server. malicious users have ways to access cookies and read their contents. or application. the client sends the information in the cookie along with the request information.

assigns the Web service a name and a description that show up in the HTML page generated when a user calls up Calc. .5 also assign descriptive text to their Web methods. ASMX is a special file name extension registered to ASP.NET (specifically.NET Framework: ed in ASMX files. to an ASP.asmx in wwwroot. the Web service’s local URL is http://localhost/calc. If you put Calc.5 is a complete Web service. attribute identifying the class that makes up the Web service. The WebService attribute also supports a Namespace parameter that can be used to change the name of the XML namespace that scopes the Web service’s members. Both take two integers as input and return an integer as well. Deploying the Web service is as simple as copying it to a directory on your Web server that is URL-addressable. It implements two Web methods: Add and Subtract.config. service class with WebMethod attributes. You can build helper methods into a Web service – methods that are used internally by Web methods but that are not exposed as Web methods themselves – by omitting the attribute.NET HTTP handler) in Machine. Implementing a Web Service Client The ASMX file shown in Figure 8.asmx.asmx demonstrates several important principles of Web service programming using the .b.‖ data or SOAP messages because the . The WebMethod attributes in Figure 8. You’ll learn more about Description and other WebMethod parameters in the section entitled ―The WebMethod Attribute. Calc.asmx in his or her browser.NET Framework deals with them for you.

asmx is a full-blown Web service when installed on a Web server outfitted with ASP. and HTTP POST.NET responded to the HTTP request for Calc. HTTP GET.NET Framework lends a hand there too. The . Its Web methods can be invoked with SOAP. copy Calc. You’ll be greeted with the screen shown in Figure 8. Underneath is a list of Web methods that the service exposes.6.asmx by generating an HTML page that describes the Web service. What happened? ASP. The name and description in the ASMX file’s Web Service attribute appear at the top of the page. and it’s capable of returning output in SOAP responses or simple XML wrappers. Calc.Calc Web service Despite its brevity. Testing a Web Service How do you test an ASMX Web service? Simple: just call it in your browser. To demonstrate.asmx to wwwroot and type http://localhost/calc.asmx In your browser’s address bar. All we need now is a way to test it out. . complete with the descriptions spelled out in the Web Method attributes.NET.

7). Type 2 and 2 into the ―a‖ and ―b‖ boxes and click Invoke. The XML returned by the Web method appears in a separate browser window .asmx as seen in Internet Explorer Click ―Add‖ near the top of the page.asmx. and ASP.NET displays a page that you can use to test the Add method (Figure 8. It even generates an HTML form that you can use to call the Add method with your choice of inputs. ASP.NET knows the method name and signature because it reads them from the metadata in the DLL it compiled from Calc.Calc.

NET generates on the fly from ASMX files enable you to test the Web services that you write without writing special clients to test them with. They also let you explore a Web service built .Test page for the Add method XML returned by the Add method The forms that ASP.

net/terraservice. It’s easy to write Web services. Writing Web service clients is even easier.NET generated for it. Web methods.asmx That’s the URL of the Microsoft TerraService. you’ll be using TerraService to build a Web service client later in this chapter. type the following URL into your browser’s address bar: http://terraservice. But do notice how much you can learn about TerraService simply by viewing the page that ASP. If you have a WSDL contract describing a Web service (or the URL of a DISCO file that . Don’t worry about the details just yet.with the . thanks to some high-level support lent by the . it’s time to learn about Web service clients – that is. or consume.NET Framework class library (FCL) and a code-generator named Wsdl. Implementing Web Service Clients Now that you’ve seen Web services up close and personal.NET Framework simply by pointing your browser to it.exe. applications that use. For kicks. an ultra-cool Web service that provides a programmatic interface to a massive database of geographic data known as the Microsoft TerraServer.

Just as Themes and Skins allow you to factor out style definitions from your page code and maintain them in a common file. the developer creates a Master File that is the template referenced by a subpage or Content Page. but content pages are declared as such within the file’s page directive. Finding greatest of n numbers Write separate programs for each of the above points. footer. Master Pages – The Master Pages feature provides the ability to define common structure and interface elements for your site. In working with Master Pages. collectively called a Theme. A page can derive from a Master Page by defining a MasterPageFile attribute on its Page directive.master file extension. and navigation in a Master Page is that these elements need only be defined once. Style changes to a site can then . you could define this in a Master Page once.aspx file extension you are used to. in a common location called a "master page". whereas content pages use the . To differentiate a Master Page from a normal page.NET pages in your application. footer. A Theme can then be applied to any site to affect the look and feel of pages and controls within the site. such as a page header.Net: a.master file extension. A page that is associated to a Master Page is called a Content Page. Themes & Control Skins Creating Themes Themes and Skins: The Themes and Skins feature of ASP. Explain the following with respect to ASP. A Master Page is a page that contains markup and controls that should be shared across multiple pages in your site. Master Pages b. Basic arithmetic operations B. as demonstrated below. Master Pages do the same for page layout. and then all pages associated to this Master Page would inherit those common elements. if all of your pages should have the same header and footer banners or the same navigation menu. The Master Pages are an easy way to provide a template that can be used by any number of ASP. instead of multiple times in duplicate code across the pages in your site. This improves the maintainability of your site and avoids unnecessary duplication of code for shared site structure or behavior. For example. to be shared by many pages in your site.Assignment SET-2 1. Master Pages use a . or navigation bar. 2. Themes & Skins Write code snippets to demonstrate the above concepts. Write a program in C# language to perform the following operations: a. a Master Page is saved under the .NET allows you to factor style and layout information into a separate group of files. The advantage of defining the header.

but not to LinkButton controls or to controls that derive from the Button object. In general. Not too many applications are designed with each page dramatically different from each other. Cascading Style Sheets A theme can also include a cascading style sheet (. you explicitly apply a named skin to a control by setting the control's SkinID property. (Default skins are matched exactly by control> <head runat = “server”> <title>STLNET</title> </head> <body> . or server control level. When you put a . Themes can also be shared with other files in the Theme folder. A .NET Themes: pplied at the application. When you build a web application. You define a style sheet using the file name extension . All pages or parts of pages in the application can then access them. Creating named skins allows you to set different skins for different instances of the same control in an application. the control skin applies to all Calendar controls on pages that use the theme. Named skins do not automatically apply to controls by type. default skins and named skins: A Default Skin automatically applies to all controls of the same type when a theme is applied to a page. You can apply these common styles individually to each and every server control or objects on each file can contain one or more control skins for one or more control types. The following are the uses of ASP. and server control styles across all the pages within the application. your applications use similar fonts.NET. without having to edit the individual pages in your site. so that a Button control skin applies to all Button controls. You can define skins in a separate file for each control or define all the skins for a theme in a single file. page. or you can use a capability provided by ASP. colors. Themes are the text-based style definitions in ASP.w3. You create .css file). There are two types of control easily maintained by making changes to the Theme.NET to centrally specify these styles. Example: This example demonstrates the application of themes to a sample ASP. the style sheet is applied automatically as part of the theme. Instead.NET web page: An ASP Page that does not use themes <% Page Language = VB” %> <html xmlns = http://www. if you create a default skin for a Calendar control.css file in the theme folder.css in the theme folder. A Control Skin is a default skin if it does not have a SkinID attribute.) A Named Skin is a control skin with a SkinID property set. it usually has a similar look-and-feel across all its pages. For example.

Describe the following with respect to Web site deployment in ASP. you can isolate different Web applications or Web sites in pools.0) When you run IIS 6. process boundaries separate each worker process from other worker processes so that when an application is routed to one application pool. which offers several configuration options to match the needs of each application. Louis . you do not have to think about applying styles to everything you do as you build because the styles are already defined centrally for you. You can instantly change the appearance of this page without changing the style of each server control on the page.NET theme that you have either built or downloaded from the Internet: <%@ Page Language = “VB” Theme = “SmokeAndGlass” %> Adding the Them attribute changes the appearance of everything on the page that is defined in an example SmokeAndGlass theme file. or a virtual directory. An application pool is a group of URLs that are routed to one or more worker processes that share the same configuration.NET Applications Creating Application Pools (IIS 6. The URLs that you assign to an application pool can be for an application. If another application fails because of the volume of requests that it receives. By using an application pool. in the case of a Web garden. for example. .NET themes. In an application pool. but which you can change with one of these new ASP. If you have multiple pages. a Web site.0) b. If.0 in worker process isolation mode. For example. Deploying ASP.<form id = “form1” runat = “server”> <h1> St. you can configure worker process recycling. you can assign specific configuration settings to a worker process (or.Net: a. you simply apply an ASP. a Web directory.NET User Group</h1><br /> <asp:Textbox ID = “Textbox1” runat = “server”/> <br /> <br /> <asp:Calendar ID = “Calendar1” runat = “server”/> <br /> <asp:Button ID = “Button1” runat = “server” Text = “Button” /> </form> </body> </html> This simple page shows some default server controls. From within the Page directive. you suspect that an application has a memory leak. Creating Application Pools (IIS 6. to a set of worker processes) that services a group of applications. 4. applications in other application pools do not affect that application. you might configure the application pools worker process to recycle when its memory use reaches a certain threshold. you can set the application pools worker process to recycle when the application exceeds a specified number of requests. which are called Application Pools.

you can make your server more efficient. 4. Use an account with the least user rights possible.0. and ensure that your applications remain available even when a worker process serving an application pool is recycled because of a faulty application. expand the local computer.1 of the .0 (IIS 6. At a command prompt. point to New. 2. This isolates the test version of the application. and then use the runas command to run IIS Manager as an administrator. As a security best practice.NET Framework version 1. Note: You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. right-click the application pool that you want to use as a template. type the name of the new application pool.1 with the operating system installation. Version 1. Click OK. Overview of Deployment process using IIS 6. In the Application pool name box.NET Framework. 3. in Application pool name box. In IIS Manager. separate the two versions into different application pools. Any Web site. type a new ID. create a unique application pool for that application. Deploying ASP. Under Application pool settings.NET Applications in IIS 6. and secure.NET applications and the Microsoft . click the appropriate setting. Web directory.msc". configure a unique user account (process identity) for each application pool.1 of the . server with the production version of the application.By creating new application pools and assigning Web sites and applications to them. and then click Application Pool. log on to your computer by using an account that is not in the Administrators group. right-click Application Pools.0 . reliable.NET Framework is installed with Windows Server 2003. Guidelines for Creating Application Pools computer. This chapter describes how to deploy ASP.0) Microsoft® Windows® Server 2003 includes support for ASP. Most ASP. enhanced security.NET applications on a newly installed server running Internet Information Services (IIS) 6. If you click Use existing application pool as template. 5.NET applications run without modification on version 1. If the ID that appears in Application pool ID box is not the ID that you want. Application pools allow you to apply configuration settings to groups of applications and the worker processes that service those applications. or virtual directory can be assigned to an application pool. create an individual application pool for each Web site. unique set of properties. Steps to create a new Application Pool: 1. such as Network Service in the IIS_WPG group. type runas /user:Administrative_AccountName "mmc %systemroot%\system32\inetsrv\iis.

NET applications.0.NET is supported on the Microsoft® Windows® Server 2003. ASP.config and Web.NET is a unified Web application platform that provides services to help you build and deploy enterprise-class Web applications and XML-based Web services. ASP.0 metabase properties.0 is shown in Figure . to run ASP. When IIS 6. you might need to configure the ASP. Datacenter Edition.NET applications on a newly installed Web server requires no understanding of earlier versions of IIS or the . and the 64-bit version of Windows® Server 2003. Datacenter Edition.1 as a part of Windows Server 2003.NET Framework version 1. the settings in the <processModel> section of the Machine. except for the <processModel> section of the Machine.NET is installed with the Microsoft . some of the attributes in the <processModel> section of the Machine.NET state service or Microsoft SQL Server™ to act as the repository for centralized state storage.NET applications.0.config file. Enterprise Edition.NET applications.0 is configured to run in worker process isolation mode. The process for deploying ASP. if your ASP. Deployment Process using IIS 6. When you configure IIS 6. Windows® Server2003. ASP.NET is not available on the following operating systems: Microsoft® Windows® XP 64-Bit Edition. Add or Remove Programs in Control Panel.0 – in the Machine. you can further configure the Web server to improve the security and availability of your ASP.0 Web server. Enterprise Edition. In addition. Standard Edition. Windows® Server2003. The deployment process presented in this section describes how to deploy ASP.config files. you will have a Web server running IIS 6. Upon completing the process described in this section.NET applications need to retain session state.0 The process for deploying new ASP.0 to use the appropriate ASP.config file are now in equivalent IIS 6. Depending on the method you select.config files are configured the same way in IIS 6.NET applications in IIS 6. Before you begin this process. the 64-bit version of Windows® Server 2003. you must also install IIS 6.0 isolation mode.NET configuration sections in the Machine.config or Web.NET applications on a newly installed IIS 6. Web Edition operating systems.0 and hosting your ASP.config file are configured in the same way as they were in IIS 5. you must configure IIS 6. However.ASP.NET Framework. complete the following steps: options.0 to run in IIS 5. However. and Windows® Server2003.NET application session state method. All the ASP.

NET session state. Step .0.Deploying ASP.NET applications on a production server.0 Note: Before deploying your ASP.NET Applications in IIS 6.NET session state by completing the following steps: Step-1: Select the method for maintaining and storing ASP.4: Configure encryption and validation keys.NET application by doing the following: 2.2: If you have decided to maintain session state with the ASP.3: If you have decided to maintain session state with SQL Server.5: Configure ASP. 2. Step .NET session state connection string. configure out-ofprocess session state with the ASP.NET to use the appropriate session state. Step .6: Secure the ASP. Install Windows Server 2003.NET application content to the Web server. Copy ASP. Create Web sites and virtual directories for each ASP. Complete the ASP. Step .NET state service. configure out-of-process session state with SQL Server. Install and configure IIS 6. Deploy the Web Server 1. 3. Install ASP. Step .NET in the Web service extensions list.NET Application Deployment .NET Applications 1. Enable common storage for ASP. Enable ASP.NET state service. perform the process outlined in this section on a test server that is configured identically to your production server. 3.

Sign up to vote on this title
UsefulNot useful