Sei sulla pagina 1di 8

MC0081 .

(DOT) Net Technologies


Que.1. Describe the following with respect to creating Web Forms in .Net environment: a. Web Form Life Cycle b. Creating a Web Form Write programs with corresponding output screens to demonstrate the above concepts. Ans A Web Form Life Cycle The life cycle begins with a request for the page, which causes the server to load it. When the request is complete, the page is unloaded. From one end of the life cycle to the other, the goal is to render appropriate HTML output back to the requesting browser. The life cycle of a page is marked by the following events, each of which we can handle our self or leave to default handling by the ASP.NET server: Load View State: The View State property of the control is populated. The View State information comes from a hidden variable on the control, used to persist the state across round trips to the server. Process Post back Data: During this phase, the data sent to the server in the posting is processed Load: Create Child Controls ( ) is called, if necessary, to create and initialize server controls in the control tree. State is restored, and the form controls show client-side data. Send Post back Change Modifications: If there are any state changes between the current state and the previous state, change events are raised via the Raise Post Data Changed Event ( ) method. Handle Post back Events: The client-side event that caused the post back is handled. Pre Render: This is the phase just before the output is rendered to the browser. Ans B Creating a Web Form First, we need to add a Web Form to a project by doing the following: Select Project, Add Web Form. In the Add New Item dialog box, enter the name Fortune.aspx for the Web Form in the Name text box. Click Open. Now that we've created a Web Form Page, we can add server controls to the page from the Web Forms toolbox. We'll add a Label control to the page by performing the follow steps: If the Toolbox window is not already open, select View, Toolbox. Drag a Label control onto the Designer surface from under the Web Forms tab in the Toolbox.
After you add the Label control, your screen should resemble and ready to use.

Que.2 Describe the following with respect to State Management in ASP.Net: a. Cookies in ASP.NET b. Session State c. Application State Ans A Cookies in ASP.NET: A cookie is used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With ASP, we can both create and retrieve cookie values. Ans B Session State: ASP.NET allows us 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, except i e scoped to the current browser session. If different users are using our application, each user session will have a different session state. In addition, if a user leaves our application and then returns later, the second user session will have a different session state from the first. We can use session state to accomplish the following tasks: Uniquely identity browser or client-device requests and map them to an individual session instance on the server. Store session-specific data on the server for use across multiple browser or client-device requests within the same session. Raise appropriate session management events. In addition, you can write application code leveraging these events. Once we add our application-specific information to session state, the server manages this object. Depending on which options you specify, session information can be stored in cookies, on an out-ofprocess server, or a computer running Microsoft SQL Server. And C Application State: ASP.NET allows us to save values using application state which is an instance of the HttpApplocationState class for each active Web application. Application state is a global storage mechanism that is accessible from all pages in the Web application. Thus, application state is useful for storing information that needs to be maintained between server round trips and between requests for pages. Application state is stored in a key/value dictionary that is created during each request to a specific URL. We can add our application-specific information to this structure to store it between page requests. Once we add our application-specific information to application state, the server manages it. 2

Que. 3 Describe the following with respect to Web Services in .Net: a. Writing and Testing a Web Service b. Implementing a Web Service Client Ans. A Writing and Testing a Web Service: Creating our first web service is incredibly easy. In fact, by using the wizards in Visual Studio. NET we can have our first service up and running in minutes with no coding. For this example - I have created a service called My Service in the/Web Services directory on my local machine. The files will be created in the /Web Services/My Service directory. A new namespace will be defined called My Service, and within this namespace will be a set of classes that define our Web Service. By default the following classes will be created: Global (in global.asax) Derived from Http Application. This file is the ASP.NET equivalent of a standard ASP global.asa file. WebService1 (in WebService1.cs) Derived from System. Web.Services.WebService. This is our Web Service class that allows us to expose methods that can be called as Web Services. Ans B) Implementing a Web Service Client: When we create and run this web service , it will be run by a web browser. However, in real life, the true aim of web service can only be achieved if we can call it from some web application or a console application. Creating a console application client for web service A utility named WSDL.exe is available in .NET to create proxies. This utility needs to know the WSDL which the proxy should use. 1. Choose Start >> Visual Studio.NET >> Visual Studio.NET Tools >> Visual Studio.NET Command Prompt to open the Visual Studio.NET command prompt. 2. Create a new directory for storing client projects. 3. In the command prompt, type: - C:> cd projects \ wsclient (directory where client project is stored) - C:\ src \ wsclient > wsdl /l:CS /n:WebBook /out:HelloworldProxy.cs http://localhost/TimeService/Hello.asmx?WSDL This command needs explanation: 3

/l:CSindicates a proxy built in C Sharp Language. /n:WebBookspecifies namespace /out:HelloworldProxy.cs specifies the proxy name. In this case, it is HelloWorldProxy. http://localhost/TimeService/Hello.asmx?WSDL is the url which is description of the web service for which proxy class is being created. The proxy class has been created. Now, we can write console applications as clients: 1) using System; 2) using WebBook; 3) 4) namespace WebBook 5) { 6) public class HelloClient 7) { 8) public static void main() 9) { 10) HelloWorld hw = new HelloWorld(); 11) Console.WriteLine ("Message returned from web service"); 12) 13) Console.WriteLine (hw.GetMessage()); 14) 15) } 16) } 17) }

4. Describe the following with respect to Web site deployment in ASP.Net: a. Creating Application Pools (IIS 6.0) b. Deploying ASP.NET Applications Ans. A Creating Application Pools (IIS 6.0) When we run IIS 6.0 in worker process isolation mode, we can isolate different Web application or Web sites in pools, which are called Application Pools. An application pool is a group of URLs that are routed to one or more worker processes that share the same configuration. The URLs that we assign to an application pool can be for an application, a Web site, a Web directory, or virtual directory. By using an application pool, we can assign specific configuration settings to a worker process that services a group of applications. We might configure the application pools worker process to recycle when its memory use reaches a certain threshold. If another application fails because of the volume of request that it receives, we can set the application pools worker process to recycle when the application exceeds specified number of requests. How to Creating Application Pools To isolate Web application on a Web site from Web application on other sites worker running on the same computer, create an individual application pool for each Web site. For enhanced security, configure a unique user account (process identify) for each application pool. Use an account with the least user right possible, such as Network services in the IIS_WPG group. If there is a test version of an application on the same server with the production version of the application pools this isolates the test version of the application. Ans. B Deploying ASP.NET Applications We can deploy ASP.NET Application in 3 different ways xCopy Deployment Precompiled Deployment Web Setup Project Xcopy deployment is the easiest, and it is often used during development to create copies of application n different servers for testing purpose. In visual studio open the website to be deployed and choose the website copy web site command. Then click the connect button to display an open website dialog box that lets to choose the destination to copy the web site to. Click the arrow buttons to copy the files from the source web site to remote web site. Advantages Avoids delays caused by compiling web pages when they are first accessed by a user. Finds compile errors before the site is deployed. Do just copy for executable files and not the source files to the server. 5

5. Write a program in C# language to perform the following operations: a. Basic arithmetic operations b. Finding greatest of n numbers Ans A . Basic arithmetic operations using System; namespace Arithmetic_Operators { class Program { static void Main(string[] args) { int num1, num2; int add, sub, mul; float div; //Accepting Values from users Console.Write("Enter first number\t\t"); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("\n\nEnter second number\t\t"); num2 = Convert.ToInt32(Console.ReadLine()); //Processing Values //Used + operator for adding values add = num1 + num2; //Used - operator for subtracting values sub = num1 - num2; //Used * operator for multiplying values mul = num1 * num2; //Used / operator for dividing values div = (float)num1 / num2; //Displaying Output Console.WriteLine("\n\n=====================\n"); Console.WriteLine("Addition\t\t{0}", add); Console.WriteLine("Subtraction\t\t{0}", sub); Console.WriteLine("Multiplication\t\t{0}", mul); Console.WriteLine("Division\t\t{0}", div); Console.WriteLine("\n=======================\n"); Console.ReadLine(); } } } Ans B. Finding greatest of n numbers using System; using System.Linq; class Program { static void Main(string[] args) { int[] numbers = { 3, 9, 5 }; int biggestNumber = numbers.Max(); Console.WriteLine(biggestNumber); Console.ReadLine(); } } 6

6. Describe the steps involved in creating classes and objects with the help of a program in C#. Answer, A class is a construct that enables us to create our 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. 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 public void SetName(string newName) { name = newName; } } class TestPerson { static void Main() { Person person = new Person(); Console.WriteLine(person.name); 7

person.SetName("John Smith"); Console.WriteLine(person.name); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } /* Output: unknown John Smith */

Potrebbero piacerti anche