July 2011 Master of Computer Application (MCA) – Semester 5 MC0081 – . (DOT) Net Technologies – 4 Credits (Book ID: B0974) Assignment Set – 1 (40 Marks) Answer all Questions Each question carries TEN marks 1. Describe the following: oImportance of ADO. Net oData Access Scenarios Disconnected Architectures Ans: Importance of ADO. Net ADO. NET (ActiveX Data Object for . NET) is a set of computer software components that programmers can use to access data and data services. It is a part of the base class library that is included with the Microsoft .
NET Framework. It is commonly used by programmers to access and modify data stored in relational database systems, though it can also access data in non-relational sources. ADO. NET is sometimes considered an evolution of ActiveX Data Objects (ADO) technology, but was changed so extensively that it can be considered an entirely new product. ADO. NET is conceptually divided into consumers and data providers. The consumers are the applications that need access to the data, and the providers are the software components that implement the interface and thereby provide the data to the consumer.
Functionality exists in the Visual Studio IDE to create specialized subclasses of the DataSet classes for a particular database schema, allowing convenient access to each field through strongly typed properties. This helps catch more programming errors at compile-time and makes the IDE’s Intelligence feature more beneficial. Data Access Scenarios The most popular data access scenario in the Internet is the one in which a user must locate a collection of data and iterate through this data a single time. When a request for data from a Web page that you have created is eceived, you can simply fill a table with data from a data store. In this case, you go to the data store, grab the data that you want, send the data across the wire, and then populate the table. In this scenario the goal is to get the data as fast as possible. 2. The second way to work with data in a disconnected architecture is to grab a collection of data and use this data separately from the data store itself. This data could be either on the client machine or the server machine. Even though the data is disconnected, you want the ability to keep the data (with all of its tables and relations in place) on the client side.
ADO. NET is a reflection of the data store itself, with tables, columns, rows, and relations all in place. When completed working on the client side copy of the data, the changes done to the data could be made persistent back into the data store from where the data was retrieved. The technology that enables the user or the programmer to perform this task is the DataSet. 2. With the help of a suitable example, explain the steps involved in editing, compiling and running a C# program. Ans: The “Hello C#” Program: you can use any editor to code the program.
It’s up to your convenience as to which editor to use. Listing 1 shows the coding for our “Hello C#” program: – Listing 1 – using System; class Hello { public static void Main() { Console. WriteLine(“Hello C#”); } } After entering the above code in an editor, you have to perform the following steps Save the file as Hello. cs. cs is an extension to indicate C-Sharp like . java for a Java source file. You have to supply this extension while saving your file, otherwise the code will not compile correctly. The saved file will be of the extension . cs. xt. Compile the code by giving the following command at the command prompt: csc Hello. cs 3. Discuss the following: •Web. config file •Global. asax Application File Ans: Web. config file Web. config is the main settings and configuration file for an ASP. NET web application. The file is an XML document that defines configuration information regarding the web application. The web. config file contains information that control module loading, security configuration, session state configuration, and application language and compilation settings. Web. onfig files can also contain application specific items such as database connection strings. ASP. Net Applications of XML have been integrated into such an extent that XML format for the exchange of data, it’s also used to store configuration settings. 1. A Web application can contain more than one Web. config file. The settings in a file apply to the directory in which it’s located, and all child directories. Web. config files in child directories take precedence over the settings that are specified in parent directories. 2. Web. config files are protected by IIS, so clients cannot get to them.
If you try to retrieve an existing http://?????. com/Web. config file, you’ll be presented with an “Access denied” error message. 3. IIS monitors the Web. config files for changes and caches the contents for performance reasons. There’s no need to restart the Web server after you modify a Web. config file. Global. asax Application File The Global. asax file is an optional file used to declare and handle application and session-level events and objects for an ASP. NET web site running on an IIS Web Server. The file contains ASP. NET program code, and is the .
NET counterpart of the Global. asa file used for ASP. The Global. asax file resides in the IIS virtual root of an ASP. NET application. At run time, upon the arrival of the first request, Global. asax is parsed and compiled into a dynamically generated . NET Framework class. ASP. NET is configured so that any direct request for the Global. asax is automatically rejected; external users cannot view or download the code in it. Code to handle application events (such as the start and end of an application) resides in Global. asax. Such event code cannot reside in the ASP.
NET page or web service code itself, since during the start or end of the application, its code has not yet been loaded (or unloaded). Global. asax is also used to declare data that is available across different application requests or across different browser sessions. This process is known as application and session state management. The Global. asax file must reside in the IIS virtual root. A virtual root can be thought of as the container of a web application. Events and state specified in the global file are then applied to all resources housed within the web application.
If, for example, Global. asax defines a state application variable, all . aspx files within the virtual root will be able to access the variable. The ASP. NET Global. asax file can coexist with the ASP Global. asa file. A Global. asax file is created in either a WYSIWYG designer or as a compiled class that is deployed in an application’s Bin directory as an assembly. However, in the latter case, the Global. asax file must refer to the assembly. Like an ASP. NET page, the Global. asax file is compiled upon the arrival of the first request for any resource in the application.
The similarity continues when changes are made to the Global. asax file: ASP. NET automatically notices the changes, recompiles the file, and directs all new requests to the newest compilation. 4. Discuss the following: •IIS Architecture •IIS Request Processing Models Ans: IIS Architecture IIS 6. 0 provides a redesigned World Wide Web Publishing Service (WWW service) architecture that can help you achieve better performance, reliability, scalability, and security for your Web sites, whether they run on a single server running IIS or on multiple servers. IIS 6. runs a server in one of two distinct request processing models, called application isolation modes. Application isolation is the separation of applications by process boundaries that prevents one application or Web site from affecting another and reduces the time that you spend restarting services to correct problems related to applications. In IIS 6. 0, application isolation is configured differently for each of the two IIS application isolation modes. Both modes rely on the HTTP protocol stack (also referred to as HTTP. sys) to receive Hypertext Transfer Protocol (HTTP) requests from the Internet and return responses.
HTTP. sys resides in kernel mode, where operating system code, such as device drivers, runs. HTTP. sys listens for, and queues, HTTP requests. For more information about HTTP. sys, see HTTP Protocol Stack. The new request-processing architecture and application isolation environment enables individual Web applications, which always run in user mode, to function within a self-contained worker process. A worker process is user-mode code whose role is to process requests, such as returning a static page or invoking an Internet Server API (ISAPI) extension or filter.
Worker processes use HTTP. sys to receive requests and send responses over HTTP. For more information about worker processes, see Worker Processes. IIS Request Processing Models Worker process isolation mode is the new IIS request processing model. In this application isolation mode, you can group Web applications into application pools, through which you can apply configuration settings to the worker processes that service those applications. An application pool corresponds to one request routing queue within HTTP. sys and one or more worker processes.
Worker process isolation mode enables you to completely separate an application in its own process, with no dependence on a central process such as Inetinfo. exe to load and execute the application. All requests are handled by worker processes that are isolated from the Web server itself. Process boundaries separate each application pool so that when an application is routed to one application pool, applications in other application pools do not affect that application. By using application pools, you can run all application code in an isolated environment without incurring a performance penalty.
For more information about application pools, see How Application Pools Work. For a visual representation of worker process isolation mode architecture, see Figure. Worker process isolation mode delivers all the benefits of the new IIS 6. 0 architecture, including multiple application pools, health monitoring and recycling, increased security and performance, improved scalability, and processor affinity. For example, the new health monitoring features can help you discover and prevent application failures, and can also help protect your Web server from imperfect applications. IIS 5. isolation mode provides compatibility for applications that were designed to run in earlier versions of IIS. When IIS 6. 0 is running in IIS 5. 0 isolation mode, request processing is almost identical to the request processing in IIS 5. 0. When a server is working in IIS 5. 0 isolation mode, application pools, recycling, and health monitoring features are unavailable. For a visual representation of IIS 5. 0 isolation mode architecture, see Figure 2. 2. The dashed line in Figure 2. 2 indicates the dependency of the worker process on the WWW service, which manages the worker process.
Use IIS 5. 0 isolation mode only if components or applications do not function in worker process isolation mode. The latter mode is designed to provide an environment in which most existing applications or sites function correctly. July 2011 Master of Computer Application (MCA) – Semester 5 MC0081 – . (DOT) Net Technologies – 4 Credits (Book ID: B0974) Assignment Set – 2 (40 Marks) Answer all Questions Each question carries TEN marks 1. Write the basic steps in building Connection Strings from Configuration Files in ADO. Net applications
Ans: If certain elements of a connection string are known ahead of time, they can be stored in a configuration file and retrieved at run time to construct a complete connection string. For example, the name of the database might be known in advance, but not the name of the server. Or you might want a user to supply a name and password at run time without being able to inject other values into the connection string. One of the overloaded constructors for a connection string builder takes a String as an argument, which allows you to supply a partial connection string which can then be completed from user input.
The partial connection string can be stored in a configuration file and retrieved at run time. Example This example demonstrates retrieving a partial connection string from a configuration file and completing it by setting the DataSource, UserID, and Password properties of the SqlConnectionStringBuilder. The configuration file is defined as follows. Note: You must set a reference to the System. Configuration. dll in your project in order for the code to run. 2. Discuss the following: •ASP. NET Compilation system •Components of ASP. NET Web page Ans: ASP. NET Compilation system The ASP.
NET compilation architecture includes a number of features including: # Multiple language support. #Automatic compilation. # Flexible deployment. #Extensible build system. Multiple language support. In ASP. NET 2. 0 you can use different languages such as Visual Basic and C# in the same application because ASP. NET will create multiple assemblies, one for each language. For code stored in the App_Code folder, you can specify a subfolder for each language. Automatic compilation. ASP. NET automatically compiles your application code and any dependent resources the first time a user requests a resource from the Web site.
In general, ASP. NET creates an assembly for each application directory (such as App_Code) and one for the main directory. (If files in a directory are in different programming languages, then separate assemblies will be created for each language. ) You can specify which directories are compiled into single assemblies in the Compilation section of the Web. config file. Flexible deployment. Because ASP. NET compiles your Web site on first user request, you can simply copy your application’s source code to the production Web server. However, ASP.
NET also provides precompilation options that allow you to compile your Web site before it has been deployed, or to compile it after it has been deployed but before a user requests it. Precompilation has several advantages. It can improve the performance of your Web site on first request because there will be no lag time while ASP. NET compiles the site. Precompiling can also help you find errors that might otherwise be found only when a user requests a page. Finally, if you precompile the Web site before you deploy it, you can deploy the assemblies instead of the source code.
You can precompile a Web site using the ASP. NET compiler tool (ASPNET_Compiler. exe). The tool that provides the following precompilation options: In-place compilation This option performs the same compilation that occurs during dynamic compilation. Use this option to compile a Web site that has already been deployed to a production server. Non-updateable full precompilation Use this to compile an application and then copy the compiled output to the production server. All application code, markup, and UI code is compiled into assemblies. Placeholder files such as . spx pages still exist so that you can perform file-specific tasks such as configure permissions, but the files contain no updateable code. In order to update any page or any code you must precompile the Web site again and deploy it again. Updateable precompilation This is similar to non-updateable full precompilation, except that UI elements such as . aspx pages and . ascx controls retain all their markup, UI code, and inline code, if any. You can update code in the file after it has been deployed; ASP. NET will detect changes to the file and recompile it. Note that code in a code-behind file (. b or . cs file) built into assemblies during precompilation, and you therefore cannot change it without going through the precompilation and deployment steps again. Extensible build system ASP. NET uses BuildProvider classes to build items such as . aspx pages, . ascx files, and global resources. You can extend and customize the ASP. NET build system to compile custom resources by creating classes that inherit from the BuildProvider class. For example, you could add a new file type and then write a BuildProvider that builds that particular type. Components of ASP. NET Web page ASP.
NET Web pages as the programmable user interface for your Web application. An ASP. NET Web page presents information to the user in any browser or client device and implements application logic using server-side code. ASP. NET Web pages are: # Based on Microsoft ASP. NET technology, in which code that runs on the server dynamically generates Web page output to the browser or client device. # Compatible with any browser or mobile device. An ASP. NET Web page automatically renders the correct browser-compliant HTML for features such as styles, layout, and so on. # Compatible with any language supported by the .
NET common language runtime, such as Microsoft Visual Basic and Microsoft Visual C#. # Built on the Microsoft . NET Framework. This provides all the benefits of the framework, including a managed environment, type safety, and inheritance. # Flexible because you can add user-created and third party controls to them. COMPONENTS OF ASP. NET Web pages In ASP. NET Web pages, user interface programming is divided into two pieces: the visual component and the logic. If you have worked with tools like Visual Basic and Visual C++ in the past, you will recognize this division between the visible portion of a page and the code that interacts with it.
The visual element consists of a file containing static markup such as HTML or ASP. NET server controls or both. The ASP. NET Web page works as a container for the static text and controls you want to display. The logic for the ASP. NET Web page consists of code that you create to interact with the page. The code can reside either in a script block in the page or in a separate class. If the code is in a separate class file, this file is referred to as the code-behind file. The code in the code-behind file can be written in Visual Basic, C#, or any other . NET Framework language.
For more information about how ASP. NET Web pages are constructed, see ASP. NET Web Page Code Model. For ASP. NET Web site projects, you deploy Web page source code to a Web server and the pages are compiled automatically the first time a user browses to any page in the site. (Optionally, you can also precompile the site so that there is no compilation delay the first time a user browses a page. ) For ASP. NET Web application projects, you must compile the Web pages before deployment and deploy one or more assemblies. 3. Describe the importance of Application State in ASP.
Net applications Ans: Application state is a data repository available to all classes in an ASP. NET application. Application state is stored in memory on the server and is faster than storing and retrieving information in a database. Unlike session state, which is specific to a single user session, application state applies to all users and sessions. Therefore, application state is a useful place to store small amounts of often-used data that does not change from one user to another. For information on saving data on a per-user basis see ASP.
NET Session State Overview and ASP. NET Profile Properties Overview. Using Application State. Application state is stored in an instance of the HttpApplicationState class. This class exposes a key-value dictionary of objects. The HttpApplicationState instance is created the first time a user accesses any URL resource in an application. The HttpApplicationState class is most often accessed through the Application property of the HttpContext class. You can use application state in two ways. You can add, access, or remove values from the Contents collection directly through code.
The HttpApplicationState class can be accessed at any time during the life of an application. However, it is often useful to load application state data when the application starts. To do so, you can put code to load application state into the Application_Start method in the Global. asax file. Alternatively, you can add objects to the StaticObjects collection via an declaration in your Web application’s Global. asax file. Application state defined in this way can then be accessed from code anywhere in your application. 4. Describe the theory of creating application pools in IIS 6. 0.
Ans: 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.
Procedures To create a new application pool 1. In IIS Manager, double-click the local computer, right-click Application Pools, point to New, and then click Application Pool. 2. In the Application pool ID box, type the name of the new application pool. 3. Under Application pool settings, click either Use default settings for new application pool or Use existing application pool as template. 4. If you selected Use existing application pool as template, from the Application pool name list box, click the application pool to be used as a template. 5. Click OK.