mc0081 spring 2013 assignment

32
Master of Computer Applications Sikkim Manipal University Directorate of Distance Education Assignment Name : Registration No. : Learning Center : Learning Center Code : Course : MCA Subject : MC0081 – . (DOT) Net Technologies Semester : V Semester Module No. : B0974 Date of submission : Marks awarded : Directorate of Distance Education Sikkim Manipal University II Floor, Syndicate House Manipal – 576104 ___________________ _ _________________ ___ ________________ ____ Signature of Coordinator Signature of Center Signature of Evaluator Gaurav Singh Jantwal ROLLNUMBER

Upload: gaurav-singh-jantwal

Post on 08-Nov-2014

191 views

Category:

Documents


0 download

DESCRIPTION

SMUDE Spring 2013 MC0081 . (DOT) Net Technologies V / 5th Semester

TRANSCRIPT

Page 1: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

Assignment

Name :

Registration No. :

Learning Center :

Learning Center Code :

Course : MCA

Subject : MC0081 – . (DOT) Net Technologies

Semester : V Semester

Module No. : B0974

Date of submission :

Marks awarded :

Directorate of Distance EducationSikkim Manipal UniversityII Floor, Syndicate House

Manipal – 576104

____________________ ____________________ ____________________Signature of Coordinator Signature of Center Signature of Evaluator

Gaurav Singh Jantwal ROLLNUMBER

Page 2: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

Comments by the Subject Evaluator:

____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Suggestions for improvement:

____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Gaurav Singh Jantwal ROLLNUMBER

Page 3: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

1. Describe the steps involved in creating classes and objects with the help of a program in C#.

Answer 1:

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 of the class

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);

Gaurav Singh Jantwal ROLLNUMBER

Page 4: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

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*/

Gaurav Singh Jantwal ROLLNUMBER

Page 5: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

2. 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.

Answer 2.

a) Web Form Life Cycle:Every request for a page made from a web server causes a chain of events at the server. These events, from beginning to end,

constitute the life cycle of the page and all its components. 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 you can handle yourself or leave to default handling by the ASP.NET server:

Initialize: Initialize is the first phase in the life cycle for any page or control. It is here that any settings needed for the duration of the incoming request are initialized.

Load ViewState: The ViewState property of the control is populated. The ViewState information comes from a hidden variable on the control, used to persist the state across round trips to the server. The input string from this hidden variable is parsed by the page framework, and the ViewState property is set. This can be modified via the LoadViewState( ) method: This allows ASP.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.

Process Postback Data: During this phase, the data sent to the server in the posting is processed. If any of this data results in a requirement to update the ViewState, that update is performed via the LoadPostData ( ) method.

Load: CreateChildControls() 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. You can modify the load phase by handling the Load event with the OnLoad method.

Send Postback Change Modifications: If there are any state changes between the current state and the previous state, change events are raised via the RaisePostDataChangedEvent ( ) method.

Handle Postback Events: The client-side event that caused the postback is handled.

PreRender: This is the phase just before the output is rendered to the browser. It is essentially your last chance to modify the output prior to rendering using the OnPreRender ( ) method.

Save State: Near the beginning of the life cycle, the persisted view state was loaded from the hidden variable. Now it is saved back to the hidden variable, persisting as a string object that will complete the round trip to the client. You can override this using the SaveViewState () method.

Render: This is where the output to be sent back to the client browser is generated. You can override it using the Render method. CreateChildControls ( ) is called, if necessary, to create and initialize server controls in the control tree.

Dispose: This is the last phase of the life cycle. It gives you an opportunity to do any final cleanup and release references to any expensive resources, such as database connections. You can modify it using the Dispose ( ) method.

Gaurav Singh Jantwal ROLLNUMBER

Page 6: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

b) Creating a Web Form: Let's create a Web Form that allows a user to input their first and last names. After entering the data into these two text fields

on the Web page, the user clicks a login button and the user's Last name, First name appear in a label below the login button.

Figure 2 shows the sample login Web Form that you will use.

Figure: Sample showing how to enter data and display it back into a label control

To build a Login form

1. Open Visual Studio and, on the Start page, click Create New Project.2. Highlight Visual Basic Projects from the treeview on the left.3. In the Templates window, click Web Application.4. For the Name of this project, type WebForms101.5. Choose the location of the machine where you wish to create this Web site.6. Click OK to begin the process of creating the new Web Application project.7. You should now have a Web Form named WebForm1.aspx in your Visual Studio project. Rename this form to Login.aspx.8. Open the Toolbox and create the form in Figure by adding the appropriate controls and setting the properties of those controls as outlined in Table 5.

Table Control is used to build the Login form

Control Type Property ValueLabel Name lblFirstName

Text First NameTextBox Name txtFirstName

TextLabel Name lblLastName

Text Last NameTextBox Name txtLastName

TextButton Name btnLogin

Text LoginLabel Name lblName

BorderStyle InsertText

Gaurav Singh Jantwal ROLLNUMBER

Page 7: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

Try It OutAt this point, you can run this application and see this Web Form appear in your browser. Although this page does not have any functionality yet, this exercise is a good test to make sure everything is running up to this point.

1. Press F5 to run this sample application.2. If you receive an error message informing you that you need a start page, right-click the Login.aspx page and click “Set” as Start Page from the context menu.

You should now see the Web Form displayed in your browser, and you can enter data into the two text fields. If you click the Login button, nothing will happen because you have not told it to do anything yet. You will next learn how to make this Login button do something.

Adding Code to the ButtonLet's add some code to the button so that it posts the data you entered in the text boxes, and fills in the appropriate data in the label below the button control.

1. End the program by closing down the browser.2. While looking at the Login page in design mode, double-click the Login button control. You will now see a code window appear with the event procedure btnSubmit. Right-click by your cursor.3. Fill in the Click event procedure so it looks like the following code.

Public Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.ClicklblName.Text = txtLastName.Text & ", " & txtFirstName.Text

End Sub

What you have just done is retrieved the text property from both the txtLastName and txtFirstName text boxes and placed the data into the label control below the Login button. This should look very familiar, if you have ever programmed in Visual Basic. In fact, the whole point of .NET is that all of the coding, whether for Windows applications or Web applications, should look the same.

Gaurav Singh Jantwal ROLLNUMBER

Page 8: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

3. Describe the following with respect to State Management in ASP.Net: a) Cookies in ASP.NET b) Session Statec) Application State

Answer 3:

a) Cookies in ASP.NET:

A cookie is often 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, you can both create and retrieve cookie values.

Create a CookieThe "Response.Cookies" command is used to create cookies.Note: The Response.Cookies command must appear BEFORE the <html> tag.

In the example below, we will create a cookie named "firstname" and assign the value "Alex" to it:<%

Response.Cookies("firstname") = "Alex"%>

It is also possible to assign properties to a cookie, like setting a date when the cookie should expire:<%

Response.Cookies("firstname") = "Alex"Response.Cookies("firstname").Expires = #May 10,2012#

%>

Retrieve a Cookie valueThe "Request.Cookies" command is used to retrieve a cookie value.

In the example below, we retrieve the value of the cookie named "firstname" and display it on a page:<%

fname = Request.Cookies("firstname")response.write("Firstname = " & fname)

%>

Output: Firstname = Alex

A Cookie with KeysIf a cookie contains a collection of multiple values, we say that the cookie has Keys.

In the example below, we will create a cookie collection named "user". The "user" cookie has Keys that contains information about a user:<%

Response.Cookies("user")("firstname") = "John"Response.Cookies("user")("lastname") = "Smith"Response.Cookies("user")("country") = "Norway"Response.Cookies("user")("age") = "25"

%>

Gaurav Singh Jantwal ROLLNUMBER

Page 9: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

Read all CookiesLook at the following code:<%

Response.Cookies("firstname")="Alex"Response.Cookies("user")("firstname")="John"Response.Cookies("user")("lastname")="Smith"Response.Cookies("user")("country")="Norway"Response.Cookies("user")("age")="25"

%>

Assume that your server has sent all the cookies above to a user. Now we want to read all the cookies sent to a user.

The example below shows how to do it (note that the code below checks if a cookie has Keys with the HasKeys property):

<!DOCTYPE html><html><body><%

dim x, yfor each x in Request.Cookies

Response.Write("<p>")if Request.Cookies(x).HasKeys then

for each y in Request.Cookies(x)Response.Write(x & ": " & y & " = " & Request.Cookies(x)(y))Response.Write("<br/>")

nextelse

Response.Write(x & " = " & Request.Cookies(x) & "<br/>")end ifResponse.Write ("</p>")

next%></body></html>

Output:firstname = Alexuser:firstname = Johnuser:lastname = Smithuser:country = Norwayuser:age = 25

Gaurav Singh Jantwal ROLLNUMBER

Page 10: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

b) Session State:

ASP.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, except that is scoped to the current browser session. If different users are using your application, each user session will have a different session state. In addition, if a user leaves your application and then returns later, the second user session will have a different session state from the first.

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.

You 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 you add your 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-of-process server, or a computer running Microsoft SQL Server.

c) Application State:

ASP.NET allows you 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. You can add your application-specific information to this structure to store it between page requests.

Once you add your application-specific information to application state, the server manages it.

Gaurav Singh Jantwal ROLLNUMBER

Page 11: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

4. Describe the following with respect to Web Services in .Net: a. Writing and Testing a Web Service b. Implementing a Web Service Client

Answer 4:

a) Writing and Testing a Web Service:

Creating your first web service is incredibly easy. In fact, by using the wizards in Visual Studio .NET you can have your first service up and running in minutes with no coding.For this example, I have created a service called “MyService” in the “/WebServices” directory on my local machine. The files will be created in the “/WebServices/MyService” directory.

A new namespace will be defined called “MyService”, and within this namespace will be a set of classes that define your Web Service. By default the following classes will be created:

Global (in global.asax)Derived from HttpApplication. This file is the ASP.NET equivalent of a standard ASP global.asax file.

WebService1 (in WebService1.cs)Derived from System.Web.Services.WebService. This is your WebService class that allows you to expose methods that can be called as WebServices.

There are also a number of files created: AssemblyInfo.cs

Contains version and configuration information for your assembly. web.config

Defines how your application will run (debug options, the use of cookies etc). MyService.disco

Discovery information for your service. WebService1.asmx

Your WebService URL. Navigate to this file in a browser and you will get back a user-friendly page showing the methods available, the parameters required and the return values. Forms are even provided allowing you to test the services through the web page.

bin\MyService.dllThe actual WebService component. This is created when you build the service.

The class for your service that is created by default is called (in this case) WebService1, and is within the MyService namespace. The code is partially shown below.

namespace MyService{

Gaurav Singh Jantwal ROLLNUMBER

Page 12: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

... /// <summary> /// Summary description for WebService1. /// </summary> [WebService(Namespace="http://codeproject.com/webservices/", Description="This is a demonstration WebService.")] public class WebService1 : System.Web.Services.WebService { public WebService1() { //CODEGEN: This call is required by the ASP+ Web Services Designer InitializeComponent(); }

...

[WebMethod] public string HelloWorld() { return "Hello World"; } }}

A default method HelloWorld is generated and commented out. Simply uncomment and build the project. Hey Presto, you have a walking talking WebService.

A WebService should be associated with a namespace. Your Wizard-generated service will have the name space http://tempuri.org. If you compile and run the service as-is you'll get a long involved message indicating you should choose a new namespace, so we add the namespace, and the WebService description as follows:

[WebService(Namespace="http://codeproject.com/webservices/", Description="This is a demonstration WebService.")]public class WebService1 : System.Web.Services.WebService{ ...

To test the service you can right click on WebService1.asmx in the Solution Explorer in Visual Studio and choose "View in Browser". The test page is shown below:

When invoked this returns the following:

Gaurav Singh Jantwal ROLLNUMBER

Page 13: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

Running demo applicationIf you downloaded the source code with this article then you will need to create a directory 'WebServices' in yourweb site's root directory and extract the downloaded zip into there. You should then have:

\WebServices\WebServices\bin\WebServices\WebService1.asmx...

Navigating to http://localhost/WebServices/WebService1.asmx won't show you the WebService because you need to ensure that the webservice's assembly is in the application's /bin directory. You will also find that you can't load up the solution file MyService.sln.

To kill two birds with one stone you will need to fire up the IIS management console, open your website's entry, right click on the WebServices folder and click Properties.

Click the 'Create' button to create a new application the press OK. The /WebServices directory is now an application and so the.NET framework will load the WebService assembly from the /WebServices/bin directory, and you will be able to load and build the MyService.sln solution.

Gaurav Singh Jantwal ROLLNUMBER

Page 14: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

b) Implementing a Web Service Client:

Let's start by creating a simple "Hello world" web service.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.

<%@ WebService Language= "C#" Class= "HelloWorld" %>using System;using System.Web.Services;

[web service (Namespace = "http://myorg.org/webservices")]public class HelloWorld : web service{

[WebMethod]public String GetMessage(){

String message = "Hello World";return message;

}}

Creating a console application client for web serviceBefore further description, let me introduce the concept of proxy class to you. This class plays a third party role for

interacting between a client and a server. It facilitates all the communication between the client and the server, be it connecting client to the server or passing parameters and methods to the server or returning results from the server. We should create a proxy as a first step to enable console application to call a web service.

Creating Web proxyA utility named WSDL.exe is available in .NET to create proxies. This utility needs to know the WSDL which the proxy

should use.a. Follow these steps to create a proxy using WSDL.exe:b. Choose Start >> Visual Studio.NET >> Visual Studio.NET Tools >> Visual Studio.NET Command Prompt to open the Visual

Studio.NET command prompt.c. Create a new directory for storing client projects.d. 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: /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.e. As the last step, Compile the proxy you have made by typing:

C: \ projects \ wsclient> csc /t:library HelloWorldProxy.cs

WSDL utility generates the source code of HelloWorldProxy.cs in result. This proxy file will contain a new definition for HelloWorld class that we developed in Listing 1.1. This class definition is different from the definition we have created before but our clients will use this definition. Instead of executing methods directly, it invokes the methods of original class (HelloWorld in this case). When you see the source code of this file, you will also notice two functions BeginGetMessage() and EndGetMessage(). These two functions have been created to facilitate calling the web services asynchronously.

Gaurav Singh Jantwal ROLLNUMBER

Page 15: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

The proxy class has been created. Now, we can write console applications as clients:

using System;using WebBook;

namespace WebBook{

public class HelloClient{

public static void main(){

HelloWorld hw = new HelloWorld();Console.WriteLine ("Message returned from web service");Console.WriteLine (hw.GetMessage());

}}

}

Since you have created a proxy class and compiled it, you no longer need to worry how this client application calls the web service or how methods and parameters are sent. The proxy class handles all the work in background. All you need to do for creating a console application client is: Create a proxy class and tell it the WSDL URL of the web service to be accessed.

Gaurav Singh Jantwal ROLLNUMBER

Page 16: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

5. Write a program in C# language to perform the following operationsa. Basic arithmetic operationsb. Finding greatest of n numbers

Write separate programs for each of the above points.

Answer 5:

a. Basic arithmetic operations

using System;using System.Collections.Generic;using System.Text;

namespace SwitchCase{

class SwitchCaseExample{

static bool ReadInteger(out int n){

string input =Console.ReadLine();n = 0;try{

n = Convert.ToInt32(input);return true;

}catch (Exception ex){

Console.WriteLine("Error in the input format\n\n");return false;

}}

static void Main(string[] args){

int a, b, opcode, result;Console.WriteLine("Program for Addition, Subtraction, Multiplication and Division\n");while (true){

Console.Write("Enter Your Choice: 1 - Add, 2 - Sub, 3 - Mul, 4 - Div: ");ReadInteger(out opcode);

if (opcode < 1 || opcode > 4) return;

Console.Write("Enter First Number:");ReadInteger(out a);Console.Write("Enter Second Number:");ReadInteger(out b);

switch (opcode){ case 1:

result = a + b; Console.WriteLine("{0} + {1} = {2}", a, b, result); break;

case 2: result = a - b; Console.WriteLine("{0} - {1} = {2}", a, b, result); break;

case 3: result = a * b; Console.WriteLine("{0} * {1} = {2}", a, b, result); break;

case 4: result = a / b;

Gaurav Singh Jantwal ROLLNUMBER

Page 17: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

Console.WriteLine("{0} / {1} = {2}\n{3} % {4} = {5}", a, b, result, a, b, a % b); break;

default: break;

}}

}}

}

b. Finding greatest of n numbers

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication23{

class Program{

static void Main(string[] args){

int i, largest;int[] array = new int[5];for (i = 0; i < 5; i++){

Console.WriteLine("Enter elements:{0}", i+1);array[i] = Convert.ToInt32(Console.ReadLine());

}largest = array[0];for (i = 0; i <5; i++){

if (array[i] > largest){

largest = array[i];}

}Console.WriteLine("The Largest number is :{0}", largest);Console.ReadLine();

}}

}

Gaurav Singh Jantwal ROLLNUMBER

Page 18: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

6. Describe the following with respect to Web site deployment in ASP.Neta. Creating Application Pools (IIS 6.0)b. Deploying ASP.NET Applications

Answer 6:

a. Creating Application Pools (IIS 6.0)

With IIS 6.0 running in worker process isolation mode, you can group Web applications into application pools. Application pools allow specific configuration settings to be applied to groups of applications, and the worker processes servicing those applications. Any Web directory or virtual directory can be assigned to an application pool.By creating new application pools and assigning Web sites and applications to them, you can make your server more efficient and reliable, and your other applications always available, even when the applications in the new application pool terminate.

Creating Application Pools (IIS 6.0) When you run IIS 6.0 in worker process isolation mode, you can isolate different Web applications 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 you assign to an application pool can be for an application, a Web site, a Web directory, or a virtual directory. In an application pool, process boundaries separate each worker process from other worker processes so that when an application is routed to one application pool, applications in other application pools do not affect that application. By using an application pool, you can assign a specific configuration setting to a worker process (or, in the case of a Web garden, to a set of worker processes), that services a group of applications. For example, you can configure worker process recycling, which offers several configuration options to match the needs of each application. If, for example, you suspect that an application has a memory leak, you 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 requests that it receives, you can set the application pools worker process to recycle when the application exceeds a specified number of requests. By creating new application pools and assigning Web sites and applications to them, you can make your server more efficient, reliable, and secure, and ensure that your applications remain available even when a worker process serving an application pool is recycled because of a faulty application.

Configuring Application Pools in IIS 6.0 (IIS 6.0) Note: This feature of IIS 6.0 is available only when running in worker process isolation mode. An application pool is a configuration that links one or more applications to a set of one or more worker processes. Because applications in an application pool are separated from other applications by worker process boundaries, an application in one application pool is not affected by problems caused by applications in other application pools. By creating new application pools and assigning Web sites and applications to them, you can make your server more efficient and reliable, as well as making your other applications always available, even when the worker process serving the new application pool has problems.

Guidelines for Creating Application Pools To isolate Web applications on a Web site from Web applications on other sites running on the same computer, create an individual

application pool for each Web site. For enhanced security, configure a unique user account (process identity) for each application pool. Use an account with the least user

rights possible, such as Network Service 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, separate the two versions

into different application pools. This isolates the test version of the application. As a design consideration, if you want to configure an application to run with its own unique set of properties, create a unique

application pool for that application.

Note: You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type

runas /user:Administrative_AccountName "mmc %systemroot%\system32\inetsrv\iis.msc".

Steps to create a new Application Pool: i. In IIS Manager, expand the local computer, right-click Application Pools, point to New, and then click Application Pool.

ii. In the Application pool name box, type the name of the new application pool. iii. If the ID that appears in Application pool ID box is not the ID that you want, type a new ID. iv. Under Application pool settings, click the appropriate setting. If you click Use existing application pool as template, in Application pool

name box, right-click the application pool that you want to use as a template. v. Click OK.

Application pools allow you to apply configuration settings to groups of applications and the worker processes that service those applications. Any Web site, Web directory, or virtual directory can be assigned to an application pool.

Gaurav Singh Jantwal ROLLNUMBER

Page 19: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

Assigning an application to an application pool: In IIS Manager, right-click the application that you want to assign to an application pool, and then click Properties. Click the Virtual Directory, Directory, or Home Directory tab. If you are assigning a directory or virtual directory, verify that Application name is filled in. If the Application name box is not filled in,

click Create, and then type a name. In the Application pool list box, click the name of the application pool to which you want to assign the Web site.

About Configuring Servers for Applications (IIS 6.0) Internet Information Services (IIS) 6.0 delivers Web hosting services through an adjustable architecture that you can use to manage server resources with improved stability, efficiency, and performance. IIS separates applications into isolated pools and automatically detects memory leaks, defective processes, and over-utilized resources. When problems occur, IIS manages them by shutting down and redeploying faulty resources and connecting faulty processes to analytical tools. IIS can run in either of two mutually exclusive modes of operation:

Worker process isolation mode. This is the default mode of IIS 6.0, isolates key components of the World Wide Web Publishing Service (WWW service) from the effects of errant applications, and it protects applications from each other by using the worker process component. Use worker process isolation mode unless you have a specific compatibility issue that makes the use of IIS 5.0 isolation mode necessary. Web sites that serve static content or simple ASP applications should be able to move to IIS 6.0 running in worker process isolation mode with little or no modification.

IIS 5.0 isolation mode. With this mode, you can run applications that are incompatible with worker process isolation mode because they were developed for earlier versions of IIS. Applications that run correctly on IIS 5.0 should run correctly on IIS 6.0 in IIS 5.0 isolation mode.Worker process isolation mode provides better default security for running Web applications than IIS 5.0 isolation mode. By default, worker processes run with the Network Service identity. The Network Service account has lower access rights than the default account for IIS 5.0 isolation mode. Web applications that run in-process in IIS 5.0 application mode run as LocalSystem. The LocalSystem account can read, execute, and change most of the resources on the computer.The default isolation mode upon installing IIS 6.0 depends on whether you perform a clean installation or an upgrade.

After a clean install of IIS 6.0, IIS runs in worker process isolation mode. After an upgrade from an earlier version of IIS 6.0, the isolation mode is the same as configured on the previously-installed

version of IIS 6.0. After an upgrade from IIS 5.0 or IIS 4.0, IIS 6.0 runs in IIS 5.0 isolation mode by default to maintain compatibility with your

existing applications.

Worker Process Isolation Mode IIS 6.0 introduces worker process isolation mode, which runs all Web applications in an isolated environment. When you run IIS in worker process isolation mode, applications can be configured to run in separate application pools. Each application pool is a logical representation of a configurable worker process and links to the applications in the pool. Worker processes operate independently of each other; they can fail without affecting other worker processes. The pooling of applications protects applications from the effects of worker processes that support other application pools. In this way, applications are protected from each other.

In worker process isolation mode, Hypertext Transfer Protocol (HTTP) requests are routed directly to an in-kernel application pool queue serving the configured application. Worker processes that serve an application pool pull the requests directly from the queue, avoiding process-switching overhead.

To further protect your WWW service, IIS 6.0 isolates critical World Wide Web Publishing Service (WWW service) components, such as the HTTP protocol stack (HTTP.sys) and WWW Service Administration and Monitoring, from the effects of third-party code running in worker processes. HTTP.sys receives and queues requests for WWW services. When a worker process enters an unhealthy state, and thus stops processing requests, HTTP.sys continues to process requests. Meanwhile, the WWW service detects that the worker process is unhealthy and shuts it down. If there is demand for a new worker process to serve requests (HTTP.sys has requests queued), the WWW service starts a new worker process to pick up the queued requests from HTTP.sys. Even though a worker process has failed, the WWW service continues to process requests and shields the user from experiencing a loss of service. IIS 6.0 worker process isolation mode delivers the following specific improvements over earlier versions of IIS:

Robust Performance Isolation prevents Web applications and Web sites from affecting each other or the WWW service. Reboots of the operating system and restarting of the WWW service are avoided.

Self - Healing Automated management provides auto-restart of failed worker processes and periodic restart of deteriorating worker processes.

Scalability Web gardens allow more than one worker process to serve the same application pool. Process Affinity enables the connection of worker processes to specific processors on multi-CPU servers. Automated Debugging The debugging feature enables the automatic assignment of failing worker processes to debugging tools. CPU Limiting This monitoring feature enables controlling the amount of CPU resources that an application pool consumes in a configured

amount of time.

Gaurav Singh Jantwal ROLLNUMBER

Page 20: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

b. Deploying ASP.NET Applications

Deploying ASP.NET Applications in IIS 6.0 (IIS 6.0) Microsoft® Windows® Server 2003 includes support for ASP.NET applications and the Microsoft .NET Framework version 1.1 with the

operating system installation. This chapter describes how to deploy ASP.NET applications on a newly installed server running Internet Information Services (IIS) 6.0. Version 1.1 of the .NET Framework is installed with Windows Server 2003. Most ASP.NET applications run without modification on version 1.1 of the .NET Framework.

Overview of Deployment process using IIS 6.0 ASP.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.NET is supported on the Microsoft® Windows® Server 2003, Standard Edition; Windows® Server2003, Enterprise Edition; Windows® Server2003, Datacenter Edition; and Windows® Server2003, Web Edition operating systems. ASP.NET is installed with the Microsoft .NET Framework version 1.1 as a part of Windows Server 2003. However, to run ASP.NET applications, you must also install IIS 6.0.

ASP.NET is not available on the following operating systems: Microsoft® Windows® XP 64-Bit Edition; the 64-bit version of Windows® Server 2003, Enterprise Edition; and the 64-bit version of Windows® Server 2003, Datacenter Edition.

The deployment process presented in this section describes how to deploy ASP.NET applications on a newly installed IIS 6.0 Web server. Before you begin this process, complete the following steps:

Install Windows Server 2003, which includes version 1.1 of the .NET Framework, with the default options. Install IIS 6.0 with the default settings in Add or Remove Programs in Control Panel.

When you configure IIS 6.0 to run in IIS 5.0 isolation mode, the settings in the <processModel> section of the Machine.config file are configured in the same way as they were in IIS 5.0 – in the Machine.config or Web.config files.

Upon completing the process described in this section, you will have a Web server running IIS 6.0 and hosting your ASP.NET applications. However, you can further configure the Web server to improve the security and availability of your ASP.NET applications.

Deployment Process using IIS 6.0 The process for deploying new ASP.NET applications on a newly installed Web server requires no understanding of earlier versions of IIS or the .NET Framework. All the ASP.NET configuration sections in the Machine.config and Web.config files are configured the same way in IIS 6.0, except for the <processModel> section of the Machine.config file. When IIS 6.0 is configured to run in worker process isolation mode, some of the attributes in the <processModel> section of the Machine.config file are now in equivalent IIS 6.0 metabase properties.

In addition, if your ASP.NET applications need to retain session state, you must configure IIS 6.0 to use the appropriate ASP.NET application session state method. Depending on the method you select, you might need to configure the ASP.NET state service or Microsoft SQL Server™ to act as the repository for centralized state storage.

The process for deploying ASP.NET applications in IIS 6.0 is shown in Figure

Deploy the Web Server i. Install Windows Server 2003. ii. Install and configure IIS 6.0. iii. Enable ASP.NET in the Web service extensions list.

Install ASP.NET Applications i. Create Web sites and virtual directories for each ASP.NET application by doing the following:

Create Web sites and home directories. Create virtual directories.

ii. Copy ASP.NET application content to the Web server.iii. Enable common storage for ASP.NET session state by completing the following steps:

Step-1: Select the method for maintaining and storing ASP.NET session state.Step-2: If you have decided to maintain session state with the ASP.NET state service, configure out-of-process session state with the ASP.NET state service.Step - 3: If you have decided to maintain session state with SQL Server, configure out-of-process session state with SQL Server.

Gaurav Singh Jantwal ROLLNUMBER

Page 21: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

Step - 4: Configure encryption and validation keys.Step - 5: Configure ASP.NET to use the appropriate session state.Step - 6: Secure the ASP.NET session state connection string.

Complete the ASP.NET Application Deployment

Ensure the security and availability of your ASP.NET applications. Verify that the ASP.NET applications were deployed successfully. Back up the Web server. Enable client access to your ASP.NET applications.

Deploying the Web Server (IIS 6.0) You must install the Web server before you can install your ASP.NET applications. In addition to installing Windows Server 2003, you must install and configure IIS 6.0 on the Web server. You must also enable ASP.NET so that the Web server can run ASP.NET applications.

Installing Windows Server 2003 (IIS 6.0)The deployment process presented here assumes that you install Windows Server 2003 with the default options. If you use other methods for installing and configuring Windows Server 2003, such as unattended setup, your configuration settings might be different. Note: When you complete the installation of Windows Server 2003, Manage Your Server automatically starts. The deployment process assumes that you quit Manage Your Server, and then further configure the Web server in Add or Remove Programs in Control Panel.

Installing and Configuring IIS 6.0 (IIS 6.0)Because IIS 6.0 is not installed during the default installation of Windows Server 2003, the next step in deploying the Web server is to install and configure IIS 6.0. The deployment process presented here assumes that you install IIS 6.0 with the default options in Add or Remove Programs in Control Panel. If you use other methods for installing and configuring Windows Server 2003, such as Manage Your Server, the default configuration settings might be different.

Install and configure IIS 6.0 by completing the following steps: Step – 1: Install IIS 6.0 with only the essential components and services. As with installing Windows Server 2003, the primary concern when installing and configuring IIS 6.0 is to ensure that the security of the Web server is maintained. Enabling unnecessary components and services increases the attack surface of the Web server. You can help ensure that the Web server is secure by enabling only the essential components and services in IIS 6.0. Step – 2: If you want to manage the Web site content by using Microsoft® FrontPage®, install FrontPage 2002 Server Extensions from Microsoft on the Web server.

Enabling ASP.NET in the Web Service Extensions List (IIS 6.0) After you install IIS 6.0, you need to enable ASP.NET. You can enable ASP.NET in Add or Remove Windows Components, which is accessible from Add or Remove Programs in Control Panel. When you enable ASP.NET by using this method, ASP.NET is also enabled in the Web service extensions list. If you enabled ASP.NET in this way, then you can continue to the next step in the deployment process.

ASP.NET is not enabled ASP.NET might not be enabled in the Web service extensions list if either of the following is true: You installed a version of the .NET Framework and ASP.NET (other than version 1.1) from a Web download or as part of an application

such as the Microsoft Visual Studio® .NET development tool. You disabled ASP.NET in the Web service extensions list because you were not running ASP.NET applications on an existing Web server.

If ASP.NET is not already enabled, view the Web service extensions list in IIS Manager and configure the status of the ASP.NET v1.1.4322 Web service extension to Allowed.

Installing ASP.NET Applications (IIS 6.0) After the Web server is deployed, you can install your ASP.NET applications. First, you must create a Web site and virtual directories for each ASP.NET application. Then you need to install each ASP.NET application in the corresponding Web site and virtual directory. When there are provisioning or setup scripts for your ASP.NET applications, use these scripts to install the ASP.NET applications on the Web server. Because the provisioning and setup scripts create the Web sites and virtual directories while installing ASP.NET applications, you do not need to perform any manual steps to install the ASP.NET applications. In this case, run the provisioning or setup scripts to install and configure the Web sites and applications, and then continue to the next step in the application deployment process. Figure 9.4 below illustrates the process for installing your ASP.NET applications.

Gaurav Singh Jantwal ROLLNUMBER

Page 22: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

Creating Web Sites and Virtual Directories for each ASP.NET Application (IIS 6.0) For each ASP.NET application, you must create a virtual directory in a new or existing Web site. Later in the installation process, you will install your ASP.NET applications into their corresponding Web sites and virtual directories.

Create the Web sites and virtual directories for your ASP.NET applications by completing the following steps: Create Web sites and home directories. Create virtual directories.

Creating Web Sites and Home Directories Using IIS 6.0 Each Web site must have one home directory. The home directory is the central location for your published Web pages. It contains a home page or index file that serves as a portal to other pages in your Web site. The home directory is mapped to the domain name of the Web site or to the name of the Web server.Create a Web site and home directory for an ASP.NET application by completing the following steps: Step – 1: Create the folder that will be the home directory for the Web site on the Web server. The folder that is the home directory of the Web site contains all of the content and subdirectories for the Web site. The folder can be created on the same computer as the Web server or on a Universal Naming Convention (UNC)–shared folder on a separate server. At a minimum, create the folder on the following:

An NTFS file system partition, which helps ensure proper security. A disk volume other than the system volume, which reduces the potential of an attack on a Web site bringing down the entire Web

server and improves performance. In a location that will not require requests for Web site content to contain /bin in the requested URL. As a security measure, ASP.NET

returns a 404 error for all requests containing /bin in the requested URL. Step – 2: Create the Web site on the server.Step – 3: If the Web site is FrontPage extended, then configure the Web site on the Web server to be FrontPage extended.

Creating Virtual Directories (IIS 6.0) A virtual directory is a folder name, used in an address, which corresponds to a physical directory on the Web server or a Universal Naming Convention (UNC) location. This is also sometimes referred to as URL mapping. Virtual directories are used to publish Web content from any folder that is not contained in the home directory of the Web site. When clients access content in a virtual directory, the content appears to be in a subdirectory of the home directory, even though it is not. For security reasons, you might want to move the Web site content to a different disk volume during the application deployment process. You can move the content to another disk volume on the Web server or to a shared folder on a separate server. You can use virtual directories to specify the UNC name for the location where the content is placed, and provide a user name and password for access rights. For each virtual directory required by the ASP.NET application, create a corresponding virtual directory on the Web server by completing the following steps: Create the folder on the Web server to contain the virtual directory content.

Ensure that you create the folder in a secure manner that does not compromise the security of the Web server. Create the virtual directory under the appropriate Web site on the server.

Copying ASP.NET Application Content (IIS 6.0) When no installation program or provisioning scripts exist for your ASP.NET application, you can copy the content of the ASP.NET application to the corresponding Web site and virtual directories that you created on the Web server.You can copy the ASP.NET application content to the Web server by using one of the following methods:

Run the Xcopy command to copy ASP.NET application content to the Web server on an intranet or internal network. Use Microsoft Windows Explorer to copy ASP.NET application content to the Web server on an intranet or internal network. Use the Copy Project command in Visual Studio .NET to copy ASP.NET application content to the Web server on an intranet or internal

network, if the application has been developed by using Visual Studio .NET.

Note: FrontPage Server Extensions must be installed on the Web server to use the Copy Project command. Use the Publish Web command in FrontPage to copy ASP.NET application content to the Web server on an intranet or over the Internet,

if the Web site that contains the application has been developed using FrontPage.

Enabling Common Storage for ASP.NET Session State (IIS 6.0) ASP.NET session state lets you share client session data across all of the Web servers in a Web farm or across different worker processes or worker process instances on a single Web server. Clients can access different servers in the Web farm across multiple requests and still have full access to session data.

You can enable common storage for ASP.NET session state by performing the following steps: i. Select the method for maintaining and storing ASP.NET session state.

Gaurav Singh Jantwal ROLLNUMBER

Page 23: MC0081 Spring 2013 Assignment

Master of Computer Applications Sikkim Manipal UniversityDirectorate of Distance Education

ii. If you have decided to maintain session state with the ASP.NET state service, configure out-of-process session state with the ASP.NET state service.

iii. If you have decided to maintain session state with SQL Server, configure out-of-process session state with SQL Server. iv. Configure the encryption and validation keys. v. Configure ASP.NET to use the session state method that you selected in Step 1. vi. Secure the ASP.NET session state connection string in the registry

Gaurav Singh Jantwal ROLLNUMBER