Friday, August 22, 2014

What is Session object? Describe in detail.



HTTP is a stateless protocol; it can't hold the user information on web page. If user inserts some information, and move to the next page, that data will be lost and user would not able to retrieve the information. For accessing that information we have to store information. Session provides that facility to store information on server memory. It can support any type of object to store. For every user Session data store separately means session is user specific.

Storing the data in Session object.

Session [“message”] = “Hello World!”;

Retreving the data from Session object.

Label1.Text = Session[“message”].ToString();
What are the Advantages and Disadvantages of Session?

Following are the basic advantages and disadvantages of using session.

Advantages:

- It stores user states and data to all over the application.

- Easy mechanism to implement and we can store any kind of object.

- Stores every user data separately.

- Session is secure and transparent from user because session object is stored on the server.

Disadvantages:

- Performance overhead in case of large number of user, because of session data stored in server memory.

- Overhead involved in serializing and De-Serializing session Data. Because In case of StateServer and SQLServer session mode we need to serialize the object before store.
Describe the Master Page.

Master pages in ASP.NET works as a template that you can reference this page in all other content pages. Master pages enable you to define the look and feel of all the pages in your site in a single location. If you have done changes in master page, then the changes will reflect in all the web pages that reference master pages. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.


Click Now


ContentPlaceHolder control is available only on master page. You can use more than one ContentPlaceHolder control in master page. To create regions that content pages can fill in, you need to define ContentPlaceHolder controls in master page as follows:

<asp:ContentPlaceHolder ID=”ContentPlaceHolder1” runat=”server”>

</asp:ContentPlaceHolder>

The page-specific content is then put inside a Content control that points to the relevant

ContentPlaceHolder:

<asp:Content ID=”Content1” ContentPlaceHolderID=”ContentPlaceHolder1” Runat=”Server”>
</asp:Content>

Note that the ContentPlaceHolderID attribute of the Content control points to the ContentPlaceHolder that is defined in the master page.

The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary .aspx pages.

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="CareerRide.master.cs" Inherits="CareerRide" %>
How you can access the Properties and Controls of Master Pages from content pages?

You can access the Properties and Controls of Master Pages from content pages. In many situations you need User’s Name in different content pages. You can set this value inside the master page and then make it available to content pages as a property of the master page.

We will follow the following steps to reference the properties of master page from content pages.

Step: 1

Create a property in the master page code-behind file.

public String UserName
{
get {
    return (String)Session["Name"];
}
set {
Session ["Name"] = value;
}
}

Step: 2

Add the @ MasterTypedeclaration to the .aspx content page to reference master properties in a content page. This declaration is added just below the @ Page declaration as follows:

<%@ Page Title=" TEST" Language="C#" MasterPageFile="~/CareerRide.master" AutoEventWireup="true" CodeFile="CareerRideWelcome.aspx.cs" Inherits="CareerRideWelcome" %>

<%@ MasterTypeVirtualPath="~/CareerRide.master" %>

Step: 3

Once you add the @ MasterType declaration, you can reference properties in the master page using the Master class. For example take a label control that id is ID="Label1"

Label1.Text= Master.UserName ;

For referencing controls in the Master Page we will write the following code.

Content Page Code.

protected void Button1_Click(object sender, EventArgs e)
{
TextBox txtName= (TextBox)Master.FindControl("TextBox1");
Label1.Text=txtName.Text;
}

To reference controls in a master page, call Master.FindControl from the content page.
What are the different method of navigation in ASP.NET?

Page navigation means moving from one page to another page in your web site and another. There are many ways to navigate from one page to another in ASP.NET.

- Client-side navigation
- Cross-page posting
- Client-side browser redirect
- Client-Side Navigation

Client-side navigation:

Client-side navigation allows the user to navigate from one page to another by using client side code or HTML. It requests a new Web page in response to a client-side event, such as clicking a hyperlink or executing JavaScript as part of a button click.

Example:

Drag a HyperLink control on the form and set the NavigateUrl property to the desired destination page.

HyperLinkControl: Source

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Welcome.aspx"> Take a test from CareerRide </asp:HyperLink>

Suppose that, this control is placed on a Web page called CareerRide.aspx, and the HyperLink control is clicked, the browser simply requests the Welcome.aspx page.

Second method of client-side navigation is through JavaScript.

Example:

Take an HTML button control on web page. Following is the HTML code for the input button.

<input id="Button1" type="button" value="Go to next page" onclick="return Button1_onclick()" />

When the Button1 is clicked, the client-side method, Button1_onclick will be called. The JavaScript source for the Button1_onclick method is as follows:

<script language="javascript" type="text/javascript">
function Button1_onclick()
{
document.location="NavigateTest2.aspx";
}

</script>

Cross-page posting:

Example:

Suppose that we have two pages, the first page is FirstPage.aspx and Second page is SecondPage.aspx. The First Page has a Button and TextBox control and its ID is Button1 and TextBox1 respectively. A Button control has its PostBackUrl property. Set this property to “~/SecondPage.aspx”. When the user clicks on Button, the data will send to SecondPage for processing. The code for SecondPage is as follows:

protected void Page_Load(object sender, EventArgs e)
{
if(Page.PreviousPage == null)
{
Label1.Text = "No previous page in post";
}
else
{
Label1.Text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
}
}

The second page contains a Label control and its ID is Label1.

The page that receives the PostBack receives the posted data from the firstpage for processing. We can consider this page as the processing page.The processing page often needs to access data that was contained inside the initial page that collected the data and delivered the PostBack. The previous page’s data is available inside the Page.PreviousPage property. This property is only set if a cross-page post occurs.

Client-side browser redirect:

The Page.Response object contains the Redirect method that can be used in your server-side code to instruct the browser to initiate a request for another Web page. The redirect is not a PostBack. It is similar to the user clicking a hyperlink on a Web page.

Example:

protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect ("Welcome.aspx");
}

In client-side browser redirect method an extra round trip to the server is happened.

Server-side transfer:

In this technique Server.Transfer method is used. The Transfer method transfers the entire context of a Web page over to another page. The page that receives the transfer generates the response back to the user’s browser. In this mechanism the user’s Internet address in his browser does not show the result of the transfer. The user’s address bar still reflects the name of the originally requested page.

protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("MyPage.aspx", false);
}

The Transfer method has an overload that accepts a Boolean parameter called preserve-Form. You set this parameter to indicate if you want to keep the form and query string data.

Thursday, August 21, 2014

Describe state management in ASP.NET.



State management may be a technique to manage a state of Associate in Nursing object on totally different request.

The communications protocol protocol is that the basic protocol of the planet Wide net. communications protocol may be a homeless protocol means that each request is from new user with relevancy net server. communications protocol protocol doesn't give you with any technique of decisive whether or not any 2 requests square measure created by a similar person.

Maintaining state is very important in any net application. There square measure 2 styles of state management system in ASP.NET.

- Client-side state management
- Server-side state management
Explain shopper facet state management system.

ASP.NET provides many techniques for storing state info on the shopper. These embrace the following:

- read state ASP.NET uses read state to trace values in controls between page requests. It works inside the page solely. you can not use read state price in next page.

- management state: you'll persist info a few management that's not a part of the read state. If read state is disabled for an impact or the page, the management state can still work.

- hidden fields: It stores knowledge while not displaying that management and knowledge to the user’s browser. This knowledge is bestowed back to the server and is accessible once the shape is processed. Hidden fields knowledge is accessible inside the page solely (page-scoped data).

- Cookies:Cookies square measure little piece of data that server creates on the browser. Cookies store a worth within the user’s browser that the browser sends with each page request to the online server.

- question strings: In question strings, values square measure keep at the top of the address. These values square measure visible to the user through his or her browser’s address bar. question strings aren't secure. you must not send secret info through the question string.
Explain server facet state management system.

The following objects square measure accustomed store the data on the server:

- Application State:

This object stores the info that's accessible to any or all pages in a very given net application. the applying object contains international variables for your ASP.NET application.

- Cache Object: Caching is that the method of storing knowledge that's used oftentimes by the user. Caching will increase your application’s performance, quantifiability, and convenience. you'll catch the info on the server or shopper.

- Session State: Session object stores user-specific knowledge between individual requests. This object is same as application object however it stores the info regarding specific user.
Explain cookies with example.

A cookie may be a touch of information that server creates on the shopper. once an internet server creates a cookie, an extra communications protocol header is distributed to the browser once a page is served to the browser. The communications protocol header feels like this:

Set-Cookie: message=Hello. when a cookie has been created on a browser, whenever the browser requests a page from a similar application within the future, the browser sends a header that appears like this:

Cookie: message=Hello

Cookie is no little bit of text info. you'll store solely string values once employing a cookie. There square measure 2 styles of cookies:

- Session cookies
- Persistent cookies.

A cookie exists solely in memory. If a user closes the online browser, the cookie delete for good.

A persistent cookie, on the opposite hand, will offered for months or maybe years. after you produce a persistent cookie, the cookie is keep for good by the user’s browser on the user’s pc.

Creating cookie

protected void btnAdd_Click(object sender, EventArgs e)


// Here txtMsgCookie is that the ID of TextBox.
// cookie names square measure case sensitive. Cookie named message is totally different from setting a cookie named Message.

The on top of example creates a cookie. The cookie disappears after you shut your application program. If you would like to make a persistent cookie, then you wish to specify Associate in Nursing expiration date for the cookie.

Response.Cookies[“message”].Expires = DateTime.Now.AddYears(1);

Reading Cookies
void Page_Load()

// Here lblCookieValue is that the ID of Label management.
Describe the disadvantage of cookies.

- Cookie will store solely string price.
- Cookies square measure browser dependent.
- Cookies aren't secure.
- Cookies will store touch of information.

Sunday, September 2, 2007

ASP.NET questions

Mast


The exam covers c#-based ASP.NET. Any of the topics below could provide appropriate questions for the GAE exam, since all are covered in ECT 310. Because of time limitations, not all topics may actually appear on the exam:
What ASP.NET can do for your Web pages
What you need to run ASP.NET
.NET framework and ASP.NET
Differences between running a script on a server and running your script on a client
Declaring and referring to a variable; Converting variables; Declaring and using an array
Arithmetic
String variable manipulation
Control structures: Branching (if-then and select case); Looping (for-next and do while); Jumping (sub-procedures and functions)
Objects and their interfaces (properties, methods and events)
Setting and retrieving object properties
Calling an object's methods
HTML server controls
ASP.NET server controls
ASP.NET validator controls
ASP.NET user controls and code-behind
Application and session objects/variables
Cookies
Debugging ASP.NET code
Accessing and updating ACCESS databases through ASP.NET
Using SQL in ASP.NET
Building a shopping cart using ASP.NET

Saturday, September 1, 2007

Sample test questions on ASP.NET

Sample test questions for ASP.NET

The test questions that follow are typical of those you’ll find for the first three chapters of our book, Murach’s ASP.NET Web Programming with VB.NET. If you’re an instructor and request the Instructor’s Guide CD, you will of course get the complete set of tests for the book.

Multiple choice

1. The protocol that’s used by a web browser and a web server to communicate in a web application is

A. HTML

B. HTTP

C. DBMS

D. IIS

2. When a dynamic web page is requested, the web server passes the request to

A. the operating system

B. the browser

C. the web application

D. the application server

3. The file that contains the Visual Basic code for a web form is the

A. code-behind file

B. aspx file

C. assembly file

D. DLL file

4. Every time a web page is requested, all but one of the following occurs. Which one is it?

A. A page class is created from the HTML code for the page.

B. The page class and the Visual Basic assembly are compiled into a DLL.

C. The compiled page is executed to create an instance of the page class.

D. HTML is generated from the instantiated page class.

5. If you want the browser to determine the exact position of each element on a form, you should use

A. absolute positioning

B. grid layout mode

C. flow layout mode

D. HTML Server controls

6. To determine if a page is being loaded for the first time, you typically

A. test the IsPostBack property of the page

B. enable view state for the page

C. save an indicator in view state

D. save an indicator in session state


7. Which event occurs when you select an item from a drop-down list?

A. Click

B. TextChanged

C. CheckedChanged

D. SelectedIndexChanged

8. View state data is stored

A. in a hidden input field in the HTML for the page

B. in the HTML for the control

C. in a temporary file on the web server

D. in browser memory

9. Consider the following statement. What directory does the page reside in?

Response.Redirect("Secure/IncomeStatement.aspx")

A. The Secure subdirectory of the host’s root directory

B. The Secure subdirectory of the current directory

C. The Secure directory at the same level in the directory structure as the current directory

D. The Secure directory one level up from the current directory

10. In which of these cases do you need to use view state with a drop-down list or list box?

A. If you want to save list items that are loaded in code the first time the page is loaded

B. If you want ASP.NET to raise the SelectedIndexChanged event when the user selects an item from the list

C. Both A and B

D. Neither A nor B

11. The validation that’s done by a required field validator is performed

A. when the user clicks a button whose CausesValidation property is set to True

B. on the client

C. on the server

D. all of the above

12. Session state is typically used for all but one of the following purposes. Which one is it?

A. To keep information about the user

B. To save objects that a user is working with

C. To keep track of pending operations

D. To keep track of the last web page that was requested

Friday, August 31, 2007

Global XML Web Services Architecture

Global XML Web Services Architecture

Introduction

Over the past five years, Microsoft has worked with other computing industry leaders to create and standardize a set of specifications for a new model of distributed computing called XML Web services. Already there are hundreds of customers deploying and running XML Web services and thousands more in the process of development. XML Web services standards, which include SOAP, XML, and WSDL, provide a high level of interoperability across platforms, programming languages and applications, enabling customers to solve integration problems easily.

But as XML Web services solutions become more global in reach and capacity – and therefore more sophisticated – it becomes increasingly important to provide additional capabilities to ensure global availability, reliability and security. Recognizing the need for standardizing these additional capabilities, Microsoft has released a new set of specifications that are the beginning of the Global XML Web Services Architecture. The aim of this architecture is to provide additional capabilities to baseline XML Web services specifications. The Global XML Web Services Architecture specifications are built on current XML Web services standards. Microsoft intends to work with key industry partners and standards bodies on these and other specifications important to XML Web services.

This paper outlines the state of XML Web services today. It demonstrates the need for a set of additional capabilities as companies deploy XML Web services to support increasingly sophisticated business processes. Finally, it addresses how Microsoft is beginning to address the need for additional capabilities with the Global XML Web Services Architecture and its supporting specifications.

XML Web Services Today

Companies are implementing XML Web services to integrate applications within the enterprise and to extend the reach of their businesses to partners and customers. This creates business efficiencies and exposes companies to new sources of revenue. Consider what the following companies are doing with XML Web services today:

Department Store Chain – Enterprise Application Integration

Background: The chain discovered that different credit approval applications had been developed in various parts of the company.

Solution: The chain exposed one credit approval application as an XML Web service. They linked this, in turn, to their point-of-sale, warehouse, and financial applications.

Business Benefits: The chain was able to expose the new credit approval application and use it with the three distinct applications operating around the company. As a result:

· Credit approvals became more consistent

· Maintenance costs decreased

· Billing back to departments became more efficient

Car Rental Company – Interoperability with Key Partner

Background: A major airline approached the car rental company about putting a link to the car reservation system on the airline’s Web site. Linking the two proprietary reservation systems presented an extreme challenge.

Solution: The car rental company created a translation engine for sending data between the two systems.

Business Benefits:

· Car rental company developed another large sales channel

· Solution got to market quickly

Some early-adopter companies are implementing next-generation XML Web services solutions that support more sophisticated business processes. The next snapshot is representative of such a service.

Insurance Company – Interoperability across Several Companies

Background: A large insurer needed to generate quotes for dental coverage and make them available on the intranet of one of their large corporate customers. The insurer had already used XML Web services to integrate its rating and quotes engine. But it had outsourced the maintenance of the dental providers’ directory and the credit rating service. These outsourced services were two vital elements for the generation of dental quotes and made the problem of their availability to clients non-trivial.

Solution: The insurance company, credit rating service, and dental provider orchestrated these applications to generate a quote that was requested by the customer on a corporate intranet.

Business Benefits: The insurance company considered this a transformational competitive advantage for the following reasons:

· It generated quotes in half the time of its competitors and provided them via a corporate intranet to one of its major customers.

· It automated existing business relationships at the level of multiple, interoperating applications. As a result, outsourcing became much more valuable, cutting the cost of quote generation by one third.

· It increased profitability in a thin-margin business.

· It provided a more seamless relationship with one of its biggest customers.

Because of application re-use and shortened time-to-market, companies can realize significant cost savings from taking an XML Web services approach to a solution. Through the integration of backend applications and key partner applications, companies are able to realize new efficiencies in the way they do business. Finally, by extending core functionality to partners, businesses are able to create new sales channels.

Trend toward Greater Sophistication

As with the adoption of any technology, XML Web services solutions are being developed to support increasingly sophisticated business processes. Apparent in the three examples above are three tiers of XML Web services development.

Tier 1 -- Enterprise Application Integration

More often than not, this is the beginning point for most companies. As in the first case study, companies initially use XML Web services to integrate internal applications. XML Web services allow them to expose legacy applications to business applications in heterogeneous environments without having to rewrite significant amounts of code.

Tier 2 – Interoperability with Key Partners

The next step for most companies is to integrate one or two key partners outside the company. Companies use XML Web services because they allow for interoperability between applications across the public Internet. Because of the lack of broadly-adopted specifications, companies must agree upon the technologies they will use to develop these interoperating XML Web services.

Tier 3 – Interoperability across Multiple Companies

Companies want to extend their computing out to more partners and customers to build business ecosystems like the one illustrated below.

Assemblies in C#

Assemblies

An assembly is the functional unit of sharing and reuse in the Common Language Runtime. It provides the Common Language Runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly. Assemblies are a fundamental part of the runtime.

In physical terms, an assembly is a collection of physical files that are owned by the assembly. These assemblies, called static assemblies, can include .NET Framework types (interfaces and classes) as well as resources for the assembly (bitmaps, JPEG files, resource files, etc.). In addition, the Common Language Runtime provides API's that script engines use to create dynamic assemblies when executing scripts. These assemblies are run directly and are never saved to disk, though you can save them to disk if you so choose.

Assembly Concepts

An assembly forms a logical unit of functionality, a “logical” dll. An assembly forms the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. Contained in an assembly is the assembly manifest, which contains all the metadata needed to specify the version requirements, security identity, and all information needed to define the scope of the assembly and resolve references to resources and classes.

It is important to understand what an assembly is not. An assembly is not a unit of application deployment. It is a unit of class deployment, much like a dll. An application is built from assemblies, and these assemblies can be packaged for deployment in several ways.

Versioning and DLL Conflicts

Currently there are two versioning problems that occur with Win32 applications. First, current applications cannot express versioning rules between pieces of an application and have these rules honored and enforced by the operating system. The current approach relies on “common-sense” coding practices that state that interface definitions are static once published and that a single piece of code must maintain backward compatibility with previous versions. Furthermore, code is typically designed so that only a single version of it can be present and executing on a machine at any given time.

The second versioning problem is the fact that there is no way to maintain consistency between the sets of components that were built together and the set that will be present at run time. These two versioning problems combine to create DLL conflicts, where installing one application can inadvertently break an existing application because a certain software component or DLL was installed that was not fully backward compatible with a previous version. Once this situation occurs, there is no support in the system for diagnosing and fixing the problem.

An End to DLL Conflicts

Windows 2000 introduced some progress toward fixing DLL conflicts. First, Windows 2000 enables you to create client applications where the dependent DLLs are located in the same directory as the application’s EXE. Windows 2000 first check for the component in the directory where the EXE is located before checking the fully qualified path or doing the normal path search. This allows components to be independent of components installed and used by other applications.

The second feature in Windows 2000 designed to partially fix DLL conflicts is System File Protection. The operating system locks the files in the System32 directory that are shipped with the OS so they cannot be inadvertently replaced when applications are installed.

The Common Language Runtime continues this evolution toward a complete solution to DLL conflicts. To solve the remaining problems that lead to DLL conflicts, the runtime:

· Allows developers to specify version rules between different software components

· Provides the infrastructure to enforce versioning rules

· Provides the infrastructure to allow multiple versions of a software component to be run simultaneously (called side-by-side execution)

The runtime solves versioning problems by using assemblies.

Assemblies and Deploying

An assembly is not a packaging format in and of itself. An assembly to be deployed is usually made up of PE files and resource files, and these files can be deployed in a number of ways. How you choose to create assemblies will dictate much of your deployment story.

You can deploy assemblies using the Windows Installer, Internet Explorer, or by copying the assembly. Assemblies can be deployed in as .cab files or as .msi files. You can also simply download or xcopy an assembly to deploy.

How the Common Language Runtime Works with Assemblies

The Common Language Runtime can only execute code in assemblies. The runtime works with two types of assemblies: static assemblies and dynamic assemblies. A static assembly is the kind of assembly you will most often work with; this is the unit produced when working with most developer environments. A static assembly consists of code modules and resources that are loaded from disk or downloaded for use by the runtime.

In contrast, a dynamic assembly is one built “on-the-fly” by the runtime from scripts on a web page or with Reflection.Emit. These dynamic assemblies can be transient---never persisted to disk---or they can be persisted and saved to disk. Persisted dynamic assemblies can be emitted with Reflection.Emit and saved for later use.

The Minimum You Need to Know About Assemblies

As a developer, you can think of an assembly as a “logical” dll. Here is a list of things you should remember about an assembly:

· It contains code that the runtime will execute. MSIL code in a PE file will not be executed if it does not have an assembly manifest associated with it. Note too that each assembly can have only one entry point (i.e. DllMain, WinMain, or Main).

· It forms a security boundary – An assembly is the unit at which permissions are requested and granted. For more information on security boundaries as they apply to assemblies

· It forms a type boundary – Every type has as part of its identity the assembly in which it resides. Therefore, a type MyType loaded in the scope of one assembly is not the same as type MyType loaded in the scope of another assembly. For more information on assemblies and type boundaries.

· It forms a reference scope boundary – The assembly’s manifest contains the rules for resolving types and resources. It specifies what types and resources are exposed outside the assembly. The manifest also enumerates other assemblies on which it is dependent.

· It forms a version boundary – The assembly is the smallest versionable unit in the Common Language Runtime; all types and resources in the same assembly are versioned as a unit. The assembly’s manifest describes the version dependencies you specify for any dependent assemblies.

· It forms a deployment unit – An application when launched only requires those assemblies it initially calls. All assemblies of an application do not have to be present at run time; other assemblies, such as localization resources, can be retrieved on demand. This allows downloaded applications to be kept simple and thin.

· It is the unit at which side-by-side execution is supported. For more information on running multiple versions of the same assembly.

Some of the information in an assembly manifest can be overridden by an application or machine-wide configuration file.

Assembly Manifest

An assembly’s manifest contains information on all items considered part of an assembly; this information is known as the assembly's metadata. The manifest indicates what items are exposed outside of the assembly and what items are accessible only within the current assembly’s scope. The assembly’s manifest also contains a collection of references to other assemblies. These references are resolved by the runtime based on information stored in the manifest. The assembly's manifest contains all information needed to use an assembly.

All assemblies have a manifest, and all applications that use the runtime must be made up of an assembly or assemblies. All files that make up the assembly must be listed in a manifest.

Figure:1

As you can see from the above illustration, the manifest can be stored in several ways. For an assembly with one associated file, the manifest is incorporated into the PE file to form a single-file assembly. A multi-file assembly can be created with either the manifest as a stand-alone file or incorporated into one of the PE files in the assembly.

From an external view (i.e. that of the assembly consumer), an assembly is a named and version-constrained collection of exported types and resources. From the internal view (i.e. that of the assembly developer), an assembly is a collection of one or more files that implement types and resources. Each assembly’s manifest enumerates the files that make up the assembly and governs how references to the assembly's types and resources are mapped to the files that contain their declarations and implementations. The manifest also enumerates other assemblies on which it depends. The existence of a manifest provides a level of indirection between consumers of the assembly and the implementation details of the assembly and renders assemblies self-describing.

The manifest contains the following information:

· Assembly name - contains a textual string name of the assembly.

· Version information -consists of a major and minor version number, and a revision and build number. These numbers are used by the runtime when enforcing version policy.

· Shared name information - contains the public key from the publisher and a hash of the file containing the manifest signed with the publisher's private key. For more information on shared names.

· Culture, processor and OS supported - contains information on the cultures, processors, and operating systems the assembly supports. For this release, this processor and OS information is ignored by the runtime.

· List of all files in the assembly - consists of a hash of each file contained in the assembly and a relative path to the file from the manifest file. Note that all files that make up the assembly must be in the same directory as the manifest file.

· Type reference information - contains information used by the runtime to map a type reference to the file that contains its declaration and implementation.

· Information on referenced assemblies - contains a list of other assemblies that are statically referenced by the assembly. Each reference includes the dependent assembly's name, metadata (version, culture, OS, etc.), and public key if the assembly is shared.

A developer can also set, in code, custom assembly attributes. These attributes are informational only and are not used by the runtime in any way. Custom attributes include:

· Title - Provides a friendly name, which can include spaces. For example, the assembly name of an assembly might be “comdlg,” while the assembly title would be “Microsoft Common Dialog Control.”

· Description - a short description of the assembly.

· Default Alias - Provides a friendly default alias in cases where the assembly name is not friendly or a GUID.

· Configuration information - consists of a string that can be set to any value for configuration information such as Retail or Debug.

· Product information such as Trademark, Copyright, Product, Company, and InformationalVersion.

Assembly Custom Attributes

You can view the attributes assigned to an assembly when it was first created, and you can add information to an assembly by using custom attributes. There are two sets of assembly attributes for this release.

The first set of assembly attributes include four fields from the assembly manifest (Title, Description, DefaultAlias, and Configuration) and five custom attributes for company or product information (Trademark, Copyright, Product, Company, InformationalVersion). These attributes are represented by nine classes in the System.Reflection namespace. The runtime adds these values to the assembly manifest when the assembly is created. You can query this information using the class System.Reflection.

Table :1

Assembly Attribute Class

Description

AssemblyCompanyAttribute

Company or additional product information

AssemblyConfigurationAttribute

Build information, such as “retail” or “debug”

AssemblyCopyrightAttribute

Copyright information for the product or assembly

AssemblyDefaultAliasAttribute

Additional information on the assembly’s name or alias

AssemblyDescriptionAttribute

Description of the product or modules that make up the assembly

AssemblyInformationalVersionAttribute

Additional or supporting version information, such as a commercial product version number

AssemblyProductAttribute

Product information

AssemblyTitleAttribute

The assembly's title

AssemblyTrademarkAttribute

Trademark information

The second set of assembly attributes are contained in the System.Runtime.CompilerServices namespace. These are custom attributes that you can add to code, and this information is added to an assembly when the assembly is created. You can put these custom attributes in any module to be included in the assembly.

Table :2 shows the attribute which include :

Assembly Attribute

Description

AssemblyCultureAttribute

Information on what cultures or languages the assembly supports

AssemblyDelaySignAttribute

Specifies that the assembly should not be fully signed when created, but rather “delay signed,” which means space is reserved for the signature which is later filled by a signing tool like the sn.exe utility

AssemblyKeyFileAttribute

Specifies the name of the file containing the key pair used to sign the assembly (i.e. give it a shared name)

AssemblyKeyNameAttribute

Specifies the name of the key container. Instead of placing a key pair in a fie, you can store it in a key container in the CSP. If you choose this option, this attribute will contain the name of the key container

AssemblyOperatingSystemAttribute

Information on which operating system the assembly was built to support.

AssemblyProcessorAttribute

Information on which processors the assembly was built to support.

AssemblyVersionAttribute

Specifies the assembly’s version information, in the format major.minor.build.rev

C# Programming(Globalizing Your ASP.NET Applications)

Taking Advantage of the System.Globalization Namespace

This is the first article of a two-part series on the globalization and localization features that are implemented in the Microsoft .NET Framework and available for ASP.NET developers. In this first part, I will look at the globalization features implemented in the System.Globalization namespace through different classes and enumerations. I also will create several example programs that show how to use these features in ASP.NET.

The second part of this article will deal with localization. I will explore how cultural information corresponds to language selections and how to create resource-based ASP.NET applications. I will create several examples to show you how to use the ResourceManager class to manage resources stored in resources files and how to use satellite assemblies.

Overview

Before I jump into the details, let me define some terms. Globalization is the process of developing a Web application core whose features and code design aren't based on a single language or locale and whose source-code base makes it easier to create editions of the application in different languages. Localization is the process of adapting a Web application so it is appropriate for the area, or locale, for which it is used. In an international market, this means translating the user interface and the content, customizing features (if necessary), and testing the results to ensure the site or program still functions correctly. A localizable application is an application that is ready for translation - all the strings and images are separated from the code.

A good localization and globalization solution is an essential part of any multilingual project, and it should be considered during the early stages of the project design. There may be different approaches to technical implementation. For example, I could create a fixed set of Web pages for different languages and store them in separate directories, or I could use online translation software. I also could use in-memory dictionaries (e.g., the Dictionary object that is part of the Microsoft Scripting Engine, the Lookup Table object, or the MessageManager object that is part of the Microsoft Commerce Server 2000) that will be accessed on a per-term basis.

Another option is to use the XML-based dictionaries. They serve the same purpose but are more flexible in terms of multilingual support. As for globalization, I can use some limited support available in the ASP object model and create COM objects. That would provide the access to National Language Support functionality of the Microsoft Windows platform and its API.

.NET Platform Features

To simplify development of multilingual applications, the .NET platform uses the concepts of culture and region. These concepts, supported by appropriate classes, define the information that contains cultural conventions and regional settings. This information is very useful for the globalization of Web applications.

To help Web developers localize their applications, the .NET platform extends the concept of resources to Web applications. Resources in .NET can be stored in files with the resources extension or in satellite assemblies and can be managed through the new ResourceManager class. Resources can be used with normal Windows applications as well as in Web applications. Using Visual Studio .NET allows developers to create all the files required for localization. By simply attaching XML-based resources (resx files) to my project, I easily can create applications that support different languages and provide a fallback for the neutral resource (default language), if the resource for a particular language cannot be found.

Globalization

The globalization features available in the .NET Framework are implemented in the System.Globalization namespace through different classes and enumerations.

The two main classes for globalization in this namespace are CultureInfo and RegionInfo. The CultureInfo class contains country-specific cultural information, such as language, calendar, sorting, and so on. Note that culture is the client-defined "value." You specify it as the locale when you install your operating system. The RegionInfo class contains region-specific information, such as region name, currency symbol, metric-system indicator, and other information. FIGURE 1 shows the members of the System.Globalization namespace.


FIGURE 1: The System.Globalization namespace members.

System.Globalization classes include Calendar, which represents time in divisions such as weeks, months, and years. There are different calendars for different cultures: GregorianCalendar, HebrewCalendar, HijriCalendar, JapaneseCalendar, JulianCalendar, KoreanCalendar, TaiwanCalendar, and ThaiBuddhistCalendar. The DateTimeFormatInfo class defines how the selected culture affects the values of the DateTime structure, NumberFormatInfo defines how the selected culture affects numeric values, StringInfo is used to iterate string values, and TextInfo defines code pages and other functions to work with text.

Language Negotiation

Language negotiation occurs when the user sets his or her preferred language, in order of preference, in the browser. Then, the browser negotiates with the server to attempt to find a page in a suitable language. For example, in Internet Explorer, you can specify a set of preferred languages by selecting Tools | Internet Options and clicking on the Languages button as shown in FIGURE 2.


FIGURE 2: Specifying language prioritization in Internet Explorer.

The server code can extract this information later because it's sent as part of the HTTP request and stored in the HTTP_ACCEPT_LANGUAGE variable. (The HTTP_ACCEPT_LANGUAGE variable is supported by most HTTP 1.1 browsers.) Sometimes language negotiation can produce results that aren't suitable for the user. For example, although the default language may be specified as French, the user may prefer to browse the English version of the site. In this case, you might provide a language-selection menu on the start page.

Some Web sites use another scenario: They try to guess a user's language preference by looking up the country extension in the IP address. For example, if the user is surfing from proxy.myprovider.co.uk (a provider based in the United Kingdom), the sites assume the user speaks English. This is often a convenient strategy, but is not necessarily the most accurate. For example, many users browse from .com, .net, or similar address suffixes that do not have any obvious relationship to a particular language.

To access a user's language preferences in ASP.NET, you can use the UserLanguages property of the HTTPRequest class that contains a weighted string array of client language preferences. The fact that they're weighted means that if the user has specified more than one language, the first one will be the default language, and others will have numeric weights indicating how far the particular language is from the default one. For example, the languages shown in FIGURE 2 have the weighted string array shown in FIGURE 3.


FIGURE 3: Language preference weights for the languages specified in FIGURE 2.

The source code for the page shown in FIGURE 3 (langpref.aspx) is provided in the download files accompanying this article (see end of article for details).

I'll use this feature to create a menu based on client languages that will be used in later examples of this article. Note that although I easily could specify the default language as the main language for an application, it is always better to give the user a chance to change the default language. FIGURE 4 contains the Visual Basic .NET code that populates a list box with the region names, extracted from the list of languages.

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim UserLangs() As String

Dim Count As Integer

Dim Pos As Integer

Dim Lang As String

If Not IsPostBack Then

UserLangs = Request.UserLanguages

For Count = 0 To UserLangs.GetUpperBound(0)

Pos = InStr(1, UserLangs(Count), ";")

If Pos > 0 Then

Lang = Left(UserLangs(Count).ToUpper, Pos-1)

Else

Lang = UserLangs(Count).ToUpper

End If

Pos = InStr(1, Lang, "-")

If Pos > 0 Then

Lang = Lang.Substring(Pos, Lang.Length-Pos)

End If

LangList.Items.Add(Lang)

Next Count

End If

End Sub

FIGURE 4: Populating the list box with region names.

Using RegionInfo Class

Now I am ready to use the RegionInfo class. I'll create an application that will allow me to check various region settings for specified regions. To do this, I need to implement the OnSelectedIndexChanged event handler for my list box that was populated with the code from FIGURE 4. The code for the event handler is shown in FIGURE 5.

Sub Index_Changed(sender As Object, e As EventArgs)

Dim Region As RegionInfo

Region = New RegionInfo(LangList.SelectedItem.Text)

AddRow(RegTable, "Name", Region.Name)

AddRow(RegTable, "EnglishName", _

Region.EnglishName)

AddRow(RegTable, "DisplayName", _

Region.DisplayName)

AddRow(RegTable, "CurrencySymbol", _

Region.CurrencySymbol)

AddRow(RegTable, "ISOCurrencySymbol", _

Region.ISOCurrencySymbol)

AddRow(RegTable, "IsMetric", Region.IsMetric)

AddRow(RegTable, "TwoLetterISORegionName", _

Region.TwoLetterISORegionName)

AddRow(RegTable, "ThreeLetterISORegionName", _

Region.ThreeLetterISORegionName)

AddRow(RegTable, "ThreeLetterWindowsRegionName", _

Region.ThreeLetterWindowsRegionName)

End Sub

FIGURE 5: This code populates a table with RegionInfo information.

On each list-box click, I create a new RegionInfo object with the specified region name and show its attributes. For example, information for the United States is shown in FIGURE 6.