Master of Computer Application (MCA) - Semester 5 MC0081 - (DOT) Net Technologies - 4 Credits
Master of Computer Application (MCA) - Semester 5 MC0081 - (DOT) Net Technologies - 4 Credits
Master of Computer Application (MCA) - Semester 5 MC0081 - (DOT) Net Technologies - 4 Credits
Ans 1.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. 2. 3. 4. 5. 6. 7. Open Visual Studio and, on the Start page, click Create New Project. Highlight Visual Basic Projects from the treeview on the left. In the Templates window, click Web Application. For the Name of this project, type WebForms101. Choose the location of the machine where you wish to create this Web site. Click OK to begin the process of creating the new Web Application project. 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 . Controls used to build the Login form Control Type Label Property Name Text TextBox Name Text Label Name Text TextBox Name Text Button Name Text Label Name BorderStyle Text btnSubmit Login lblName Insert Label2 Last Name txtLast Value Label1 First Name txtFirst
Try It Out
At 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 Button Let'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 btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click lblName.Text = txtLast.Text & ", " & txtFirst.Text End Sub What you have just done is retrieved the text property from both the txtLast and txtFirst 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. Ans 2.a) Cookies in ASP.net A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site. Imagine that when users request a page from your site, www.contoso.com, your application sends not just a page, but a cookie containing the date and time. When the user's browser gets the page, the browser also gets the cookie, which it stores in a folder on the user's hard disk. Later, the user requests a page from your site again. When the user enters the URL www.contoso.com, the browser looks on the local hard disk for a cookie associated with the URL. If the cookie exists, the browser sends the cookie to your site along with the page request. Your application can then determine the date and time that the user last visited the site. You might use the information to display a message to the user, check an expiration date, or perform any other useful function. Cookies are associated with a Web site, not with a specific page, so the browser and server will exchange the www.contoso.com cookie information no matter what page the user requests from your site. As the user visits different sites, each site might send a cookie to the user's browser as well; the browser stores all the cookies separately.
Ans 2.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 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-ofprocess server, or an a computer running Microsoft SQL Server.
Ans.2.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. Ans 3.a) Web Services allow access to software components through standard web protocols such as HTTP and SMTP. Using the Internet and XML, we can now create software components that communicate with others, regardless of language, platform, or culture. Until now, software developers have progressed toward this goal by adopting proprietary componentized software methodologies, such as DCOM; however, because each vendor provides its own interface protocol, integration of different vendors' components is a nightmare. By substituting the Internet for proprietary transport formats and adopting standard protocols such as SOAP, Web Services help software developers create building blocks of software, which can be reused and integrated regardless of their location.
In this chapter, we describe the .NET Web Services architecture and provide examples of a web service provider and several web service consumers. Ans 3.b) Implementing the Web Service Client Although being able to access a Web Service from a Web browser is nice, a more realistic use is to create custom client programs that access a Web Service remotely, such as Web pages and standalone applications. To demonstrate how to create such programs, we'll create two different clients for our TimeUtils Web Service: a console application and a Web page. TIP You can create Web Service clients easily by using Visual Studio.NET; we'll explain how to create them a little later. However, to show some of the "plumbing" behind Web Services, let's continue using a text editor to create our client programs. Before creating the client to our TimeUtils application, we need to create a proxy class. A proxy class allows us to call the GetTime method without worrying about how to connect to the server and how to pass and return parameters to and from the method. In general, a proxy is an object that wraps up method calls and parameters, forwards them to a remote host, and returns the results to us. Proxies serve the role as a middleman on the client computer. .NET comes with a special utility called WSDL.exe for creating Web Service proxies. As you might imagine from the utility's name, WSDL.exe takes a Web Service's WSDL description and creates a proxy. Follow these steps to create the proxy with WSDL.exe: 1. Open a Visual Studio.NET command prompt (from the Start menu, choose Visual Studio.NET, Visual Studio.NET Tools, and then Visual Studio.Net Command Prompt). This DOS command prompt contains all the paths for the .NET tools. 2. Create a new directory for the client projects, such as C:\src\timeclient. 3. Type the following command at the prompt (try to fit the entire command at the second prompt onto one line): 4. C:>cd src\timeclient 5. C:\src\timeclient> wsdl /l:CS /n:WebBook 6. /out:TimeProxy.cs http://localhost/TimeService/TimeUtils.asmx?WSDL This command creates the TimeProxy.cs file, which you can use in your client applications: /l:CS tells the utility to create the proxy using C#. /n:WebBook specifies a namespace for the WSDL tools to use when it creates the proxy class. You can use any namespace name you want.
/out:TimeProxy.cs specifies the name of the output file. The last parameter is an URL for getting a WSDL description of the Web Service. You can also specify a file containing WSDL. However, if you use an URL, as in this example, the utility will automatically browse to the Web address and use the WSDL file that it finds.
7. Compile the new proxy file: C:\src\timeclient> csc /t:libarary TimeProxy.cs The proxy that the WSDL.exe utility creates should look like the file shown in Listing 3. Listing 3An Automatically Generated Proxy Class for the TimeUtils Client 1: //---------------------------------------------------------------------2: // <autogenerated> 3: // 4: // 5: // 6: // lost 7: // Changes to this file may cause incorrect behavior and will be if the code is regenerated. This code was generated by a tool. Runtime Version: 1.0.2914.16
8: // </autogenerated> 9: //---------------------------------------------------------------------10: 11: // 12: // This source code was auto-generated by wsdl, Version=1.0.2914.16. 13: // 14: namespace WebBook { 15: 16: 17: 18: 19: 20: 21: 22: [System.Web.Services.WebServiceBindingAttribute( Name="TimeUtilitiesSoap", using System.Diagnostics; using System.Xml.Serialization; using System; using System.Web.Services.Protocols; using System.Web.Services;
23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
38: ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped) ] 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: [System.Diagnostics.DebuggerStepThroughAttribute()] public string EndGetTime(System.IAsyncResult asyncResult) { object[] results = this.EndInvoke(asyncResult); return ((string)(results[0])); } [System.Diagnostics.DebuggerStepThroughAttribute()] public System.IasyncResult BeginGetTime(System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("GetTime", new object[0], callback, asyncState); } public string GetTime() { object[] results = this.Invoke("GetTime", new object[0]); return ((string)(results[0]));
The proxy file contains a new definition for the TimeUtilities class, different from the one created earlier in Listing 1. This new definition is the version that all our client programs will use. Although this new class is defined differently than the original created for the Web Service, this new TimeUtilities class will work the same way for any client program that uses it. Rather than execute code directly, this new class will call the Web Service to execute each method. Notice also the two new methods in the proxy class, BeginGetTime (Lines 4450) and EndGetTime (Lines 5256). These methods are created so that we can call the Web Service asynchronously. This means that we can call the Web Service in our client program and then do other work immediately. Then, when the Web Service returns a result, we can process the results at that time. This asynchronous method for calling remote Web Services might not be responsive because of a slow network connection. Now that we've created our proxy class, we can create client programs that use our Web Service. To begin, let's create a simple console application to call the Web Service. The client is shown in Listing Ans 4.a) When you run IIS 6.0 in worker process isolation mode, you 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 you assign to an application pool can be for an application, a Web site, a Web directory, or 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, application in other application in other application pools do not affect that application .
By using an application pool, you can assign specific configuration settings to a worker process that services a group of applications. For example, you can configure worker process recycling, which offers several configuration options to match the need 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 request that it receives, you can set the application pools worker process to recycle when the application exceeds 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 application remain available even when a worker process serving an application pool is recycled because of faulty application.
. An application pool is configuration that links one or more application 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 problem caused by application in other application pools.
By creating new application pools and assigning Web site and applications to them, you can make your server more efficient and reliable, as well as making your other application always available, even when the worker process serving the new application pool has problems.
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. As a design consideration , if you b. Deploying ASP.NET 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 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. Step to create a new Application Pool :
1. In IIS Manger, expand the local computer, right-click Application Pools, point to new and then click Application Pool.
2. In the application pool name box, type the new application tool.
3. If the ID that appears in the Application pool Id box is not the ID that you want, type a new ID.
4. Under Application pool setting, click the appropriate setting. If you click Use existing application tool as template, in the application pool name box, right click the application pool that you want to use as a template.
5. Click OK.
Application pool allows you to apply configuration settings to group 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.
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 and 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.
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.9 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 application mode run as local system. The local system 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.
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 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 the queued request form 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 process. 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.
Ans 4.b) Hello, in this article i have tried to explain, how a web application is deployed on to web server. Deployment refers to the process of copying an asp.net web application from the development system to the server on which the application will be run. There are several way we can deploy our web application We can deploy ASP.NET Application in 3 different ways xCopy Deployment Precompiled Deployment Web Setup Project The choice of best deployment alternative depends upon particular need of each application. Xcopy deployment is the most easiest, and it is often used during development to create copies of an application n different servers for testing purpose. For small application xcopy deployment may be the best choice.
Precompiled deployment has several advantages over XCopy deployment. Eg. Precompiled deployment is always gives better performance for the first users of the site at the same time it is more secure as we dont need to copy our source code files on to server. If our application deployed on one or few servers then precompiled deployment is usually best choice. When we are going to deploy our application on number of servers then creating a setup program is a very handy tool. Although creating this setup program is much tedious and involves considerable working, the deployment from this setup program becomes very easier. xCopy Deployment To manually copy the files of an asp.net web site to a server. We can use the xcopy command from a command prompt. Then we can use IISs (Internet Information Serve management console t o create a virtual directory thats mapped to the directory that you copied the web site to. It is easier to create a batch file for the xcopy command. Then after we can run that batch file at given time we make changes to the application and want to deploy the updated code. We can also perform xcopy deployment from visual studio by using copy website command. To perform xcopy we use copy web site command. This command lets us to copy website to file system, local IIS, FTP or remote IIS website. At the same time we can copy all or selected files. How to use this command 1. 2. 3. 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. Publish Web Site The publish web site command lets us to precompile an asp.net application and copy the precompiled assemblies to a target server. This is the easiest way to use the precompiled deployment feature. Deploys precompiled assemblies to the specific server Lets us to deploy the web site without source code files It is done either from publish web site command or from command prompt using the aspnet_compiler command
Ans 5.a) Basic Arithmetic Operation in C# public static class Operation { public static bool DoSequenceOfAnd(params bool[] sequenceOfBooleanValue)
{ bool andResult = true; Array.ForEach(sequenceOfBooleanValue, (item) => { andResult &= item; }); return andResult; } public static bool DoSequenceOfOr(params bool[] sequenceOfBooleanValue) { bool orredResult = default(bool); Array.ForEach(sequenceOfBooleanValue, (item) => { orredResult |= item; }); return orredResult; } public static bool DoSequenceOfXOr(params bool[] sequenceOfBooleanValue) { bool xoredResult = default(bool); Array.ForEach(sequenceOfBooleanValue, (item) => { xoredResult ^= item; }); return xoredResult; } public static T DoSequenceOfPlus<T>(params T[] sequenceOfTValues) where T : struct { T additionResult = default(T); Func<T, T, T> adder = ExpressionGenerator.AdditionExpression<T>(); Array.ForEach(sequenceOfBooleanValue, (item) => { additionResult = adder(item, additionResult); }); return additionResult; } public static T DoSequenceOfMultiply<T>(params T[] sequenceOfTValues) where T : struct { dynamic multiplicationResult = (DoSequenceOfPlus<int>(default(int), 1)); Func<T, T, T> multiplier = ExpressionGenerator.MultiplicationExpression<T>(); Array.ForEach(sequenceOfBooleanValue, (item) => { multiplicationResult = multiplier(item, multiplicationResult); }); return multiplicationResult; } } Ans 5.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(); } } } Ans 6) 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
name = newName; } } class TestPerson { static void Main() { Person person = new Person(); 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 */