Create Free Blog | Random Blog »   Report Abuse | Login   

 
 

Creating and Applying Themes in ASP.NET ?

June 30th, 2009

Creating Themes in ASP.NET à

Hi!

Here i will show you step by step procedure how to use

Creating Themes in ASP.NET in visual studio 2005 / 2008

The use of creating themes is to format the controls in asp.net pages…

__________________________________________________

Here I am using Visual Studio 2008 but there is no condition you can use Visual Studio 2005 also.

So follow these steps to create State Implementation

The Steps are:

1- Start -> All Programs -> Visual Studio 2005 or Visual Studio 2008

2- Now go to File Menu -> New -> Web Site

3- Under Visual Studio Installed Template-> Choose ASP.NET WEB SITE -> Choose File System from the location combo box -> Set the path by the browse button - > Choose the language from the Language ComboBox (Visual C# , Visual Basic , J #)

Choose Visual C#

4 - Click on the OK Button:-

First you have to learn XML and HTML to work with ASP .NET_

I have used <!– text –> to make the text as comment this is the way to make comment in this code …

This is the Source Code window and in this page you will se this code…

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Type your webpage title here</title>  <!– Here you can specify your page title in between title tag
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<!– In between div tags you can manage your web controls like buttons, labels, picture

Box, ImageMap etc –>


</div>
</form>
</body>
</html>

See here is a tab named Design in the bottom of this page

5- Click on this tab and you will see a blank web page where you can drag any control from the toolbox (which is in the left side of this window)

Open Web.config file and write true in place of false, See

<compilation debug=”true”>

6- Drag two Label, one TextBox and one button control in the design window or in the source window

7-Now the source window should be look like this :

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head runat=”server”>

<title>Creating Themes</title>

asp:Label ID=”Label1″ runat=”server” Text=”Enter Your Name in the Text Box”></asp:Label><br />

<br />

<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox><br />

<br />

<asp:Button ID=”Button1″ runat=”server” Text=”Click To Submit” /></div>

8- Now go to solution explorer and right click on the web site and choose Add New Item

and add a .skin extension file .

9- Now type this code in the .skin extension file

<asp:label runat=”server” width=”350px” height=”50px” font-bold=”True” font-size=”Large” forecolor=”Red” backcolor=”Blue”/>

<asp:button runat=”server” forecolor=”Blue” backcolor=”Silver”/>

<asp:textbox runat=”server” font-bold=”True” font-size=”Medium” forecolor=”Blue” backcolor=”Silver” font-italic=”True”/>

10- Now you have to add one line in the Default.aspx page for applying the theme on the page…

See how to apply the theme…

<link href=”StyleSheet.css” rel=”stylesheet” type=”text/css” />

Type this line just after <title> tag like this

<title>Creating Themes</title>

<link href=”StyleSheet.css” rel=”stylesheet” type=”text/css” />

11 - Now run your web site by Ctrl + F5

OUT PUT

10-Now you will see that your control are now formatted …

11- Close web browser

12-Close visual studio

Thanks!

–Nikhil Kumar

Share SocialTwist Tell-a-Friend 

Brief about .NET Framework 2.0 ?

June 28th, 2009

Table of Contents

ú Introduction

ú Overview

ú .Net Framework Remoting

ú Globalization

ú Manifest-Based Activation

ú New Window-based Form controls

ú Conclusion

Introduction:

The new version of .NET Framework which is .NET Framework 2.0

introduced with lot of new features which is now more affective, useful

then the old version of .NET which is .NET Framework 1.1.

Here we define the new features which are introduced in .NET 2.0…

We hope it will useful and complete…

.Net Framework is an integrated and managed environment for the

development and execution of your code.

.Net allocates memory for the storage of data and instructions, grants or

denies the appropriate permissions to your application, initiates and

manages application execution and manages the re-allocation of memory

from resource that are no longer needed.

Overview:

Ø .NET Framework

§ .Net provides development tools, run-time environment, server infrastructure and intelligent software which enable you to build application for various platform and devices.

§ “The .NET Framework is an integral Windows component that supports developing, deploying and running the applications and XML Web services.”

Changes in 2.0 in comparison with 1.1:

Here are the changes which are performed in the new version of .NET Framework 2.0:

l Numerous API changes.

l A new hosting API for native applications wishing to host an instance of the .NET runtime. The new API gives a fine grain control on the behavior of the runtime with regards to multithreading, memory allocation, assembly loading It was initially developed to efficiently host the runtime in Microsoft SQL Server, which implements its own scheduler and memory manager.

l Full 64-bit support for both the x64 and the IA64 hardware platforms.

l Language support for generics built directly into the .NET CLR.

l Many additional and improved ASP.NET web controls.

l New data controls with declarative data binding.

l New personalization features for ASP.NET, such as support for themes, skins and webparts.

l .NET Micro Framework - a version of the .NET Framework related to the Smart Personal Objects Technology initiative.

l Partial classes

l Anonymous methods

l Generics

l Data Tables

Net Framework Remoting:

Ø .Net Framework Remoting:

§ .NET Remoting is a Microsoft application programming interface (API) for interprocess communication released in 2002 with the 1.0 version of .NET Framework. It is one in a series of Microsoft technologies that began in 1990 with the first version of Object Linking and Embedding (OLE) for 16-bit Windows.

§ .Net remoting is used to enable communication between different applications .

§ Computers may be part of network, .NET Remoting is an enabler for application communication.

.Net Remoting Architecture:

Features of .NET Framework Remoting:

Ø Multiple transfer mechanisms – HTTP/TCP

If there is no web server running – put traffic on port 80

Ø Multiple encodings – SOAP/ Binary

(Your own-serialization)

Ø .NET Remoting is more flexible (more activation and deployment options)

Ø .NET Remoting is customizable (you can add logging or other features)

Ø .Net Remoting enables you to work with stateful objects

Ø Interface description does not have to be manually coded in any way, as metadata can be extracted from running servers, or from any .Net assembly

Ø One of the major benefits is that it’s centralized around well-known and well-defined standards like HTTP and is directly tied to the .Net Framework

Globalization:

Ø What is Globalization?

§ Globalization (globalization) in its literal sense is the process of transformation of local or regional phenomena into global ones. It can be described as a process by which the people of the world are unified into a single society and function together.

§ It is an process in which it run across all platforms and all sites with minimum or no modification to the application.

§ It also makes locally prevailing information on culture. Like location information and language used in particular location.

Features of Globalization:

Ø Feature introduced in .Net 2.0:

§ CultureAndRegionInfoBuilder class

§ Support for custom cultures enables you to define and deploy culture-related information as needed. This feature is useful for creating minor customizations of existing culture definitions, and creating culture definitions that do not yet exist in the .NET Framework. For more information, see the CultureAndRegionInfoBuilder class.

§ System.Text namespace

§ Encoding and decoding operations map a Unicode character to or from a stream of bytes that can be transferred to a physical medium such as a disk or a communication line. If a mapping operation cannot be completed, you can compensate by using the new encoding and decoding fallback feature supported by several classes in the System.Text namespace.

§ UTF8Encoding class

§ Members in the UTF8Encoding class, which implements UTF-8 encoding, are now several times faster than in previous releases. UTF-8 is the most common encoding used to transform Unicode characters into bytes on computers.

§ Support Latest Normalization Standard

§ The .NET Framework now supports the latest normalization standard defined by the Unicode Consortium. The normalization process converts character representations of text to a standard form so the representations can be compared for equivalence.

§ CultureInfo class

§ The GetCultureInfo method overload provides a cached version of a read-only CultureInfo object. Use the cached version when creating a new CultureInfo object to improve system performance and reduce memory usage.

Manifest – Based Activation:

l Overview

Manifest is an XML based, database driven Content

Management System (CMS) for satisfying corporate

communications needs, including Internet and Intranet.

Traditional web development packages focus on creating

a Website one page at a time, often immersing the author

in complex HTML code

Manifest – Based Activation:

l ClickOnce

Manifest-based activation is essential for supporting ClickOnce

applications. Traditionally, applications are activated through

a reference to an assembly that contains the

application’s entry point.

l Web Application

The manifest-based activation model uses an application manifest for activation rather than an assembly. A manifest fully describes the application, its dependencies, security requirements, and so forth. The manifest model has several advantages over the assembly-based activation model, especially for Web applications.

Manifest – Based Activation:

l APIs

Manifest-based activation is provided by a set of APIs that allow managed hosts to activate applications and add-ins described by a manifest. These APIs contain a mixture of both new classes and extensions to existing classes.

l This activation model also invokes an entity called a Trust Manager that performs the following tasks:

l Determines whether an application is allowed to be activated. This decision can be made by prompting the user, querying policy, or by any other means deemed appropriate for a given Trust Manager.

l Sets up the security context to run an application in. Most commonly, this step involves setting up a code access security (CAS) policy tree on the application domain in which the application will run.

New Window-Based Form Control:

.Net Framework 1.0 was released on January 16,2002

which was its first version. After that version 1.1 was

released on April 24,2003 which was released together

With Windows 2003 Server.

Latest version is .net framework 2.0 which was

released on November 7, 2005 with Visual Studio 2005

and SQL Server 2005.

New Window-Based Form Control


Overview:

Ø Debugger Edit and Continue Support

Ø I/O Enhancements

Ø .NET Framework Remoting

Ø Click Once Deployment

Ø Masked Text Box

Ø Sound Player Class

New Controls:

Ø Debugger Edit and Continue Support

l The .NET Framework 2.0 reintroduces the Edit and Continue feature

that enables a user who is

debugging an application in Visual Studio to

make changes to source code while executing in

Break mode.

Ø I/O Enhancements

l You can now use the classes in the

System.IO.Compression namespace to read

and write data with the GZIP compression

and decompression standard, described in

the IETF RFC 1951 and RFC 1952

specifications.

Ø .NET Framework Remoting

§ .NET Framework Remoting now supports IPv6

addresses and exchange of generics types.

Ø Click Once Deployment

You can deploy Windows client and commandline

applications. There are new Publish Project

commands on the Build and Project menus in

Visual Studio.

Ø Masked Text Box

Uses a masked definition to distinguish between a valid

and invalid user input.

Ø Sound Player Class

The SoundPlayer class enables you to play sounds file in

.wav format and enables you to load or play sounds

asynchronously.

Ø Table Layout Panel

The TableTayOut panel controls arranges its contents in a grid.

Because the layout is performed both at design time and run time, it

can change dynamically as the application environment changes.

Some Other Controls in .NET 2.0:

l ContextMenuStrip control

The ContextMenuStrip is an enhanced shortcut menu used with ToolStrip controls

l DataGridView control

The DataGridView control provides a powerful and flexible way to display data in a

tabular format. It can be used to show read-only views of a small amount of data, or

it can be scaled to show editable views of very large sets of data. The data can reside

in an external data source or be added directly to the control. For more information,

see DataGridView Control Overview (Windows Forms).

l Layout panels

The FlowLayoutPanel control arranges its contents in a horizontal or vertical flow

direction. The TableLayoutPanel control arranges its contents in a grid. Because the layout is performed both at design time and run time, it can change dynamically as the application environment changes. For more information, see FlowLayoutPanel Control Overview and TableLayoutPanel Control Overview

l ListView control

The ListView control now supports three features provided by Windows XP and the

Windows Server 2003 family

l MenuStrip control

The MenuStrip is an enhanced menu system that is used with ToolStrip controls.

l SplitContainer control

The Windows Forms SplitContainer control can be thought of as a composite; it is two panels separated by a movable bar. When the mouse pointer is over the bar, the cursor changes to show that the bar is movable. Use it to create complex, resizable user interfaces that are most effective for displaying and browsing information. For more information, see SplitContainer Control (Windows Forms).

l StatusStrip control

The StatusStrip is an enhanced status bar used with ToolStrip controls.

l ToolStrip control

ToolStrip controls are toolbars that can host menus, controls, and user controls in your Windows Forms applications. The ToolStrip and its associated classes let you create toolbars and other user interface elements that can have a Windows XP, Office, Internet Explorer, or custom look of the interface. For more information, see ToolStrip Control Overview (Windows Forms).

l ToolStripContainer control

The ToolStripContainer provides built-in rafting and docking of ToolStrip, MenuStrip, and StatusStrip controls.

l WebBrowser control

The WebBrowser control lets you host Web pages in your Windows Forms applications

Conclusion:

From the discussion in this article, several evolving trends related to the new version of .Net 2.0 are observed. First, .NET 2.0 will be based on the simple controls and supports only some specify languages

– Nikhil Kumar

Share SocialTwist Tell-a-Friend 

.NET 2.0 Controls Vs .NET 1.1 Controls ?

June 28th, 2009

New .NET FRAMEWORKS Controls…

(Here I will tell you the new controls of .NET framework which are introduced in .NET Framework 2.0)

.NET FRAMEWORK

.Net Framework 1.0 was released on January 16,2002

which was its first version. After that version 1.1 was

released on April 24,2003 which was released together

With Windows 2003 Server.

Latest version is .net framework 2.0 which was

released on November 7, 2005 with Visual Studio 2005

and SQL Server 2005.

New Controls

Ø Debugger Edit and Continue Support

Ø I/O Enhancements

Ø .NET Framework Remoting

Ø Click Once Deployment

Ø Masked Text Box

Ø Sound Player Class

{After source code edits are applied do not need this first argument and is similar to

the use of instance method calls.

In addition, the invocation of methods through

the use of delegates is now more efficient.}

Ø Debugger Edit and Continue Support

  • The .NET Framework 2.0 reintroduces the Edit and Continue feature

that enables a user who is

debugging an application in Visual Studio to

make changes to source code while executing in

Break mode.

{Improvements have been made to the

Usability and functionality of various I/O

Classes. It is now easier for users to read and

write text files and obtain information about

a drive. }

Ø I/O Enhancements

  • You can now use the classes in the

System.IO.Compression namespace to read

and write data with the GZIP compression

and decompression standard, described in

the IETF RFC 1951 and RFC 1952

specifications.

Ø .NET Framework Remoting

    • .NET Framework Remoting now supports IPv6

addresses and exchange of generics types.

{ClickOnce deployment allows you to deploy

self-updating Windows applications that can be

installed and run as easily as Web applications.}

Ø Click Once Deployment

    • You can deploy Windows client and commandline

applications. There is new Publish Project

Commands on the Build and Project menus in

Visual Studio

Ø Masked Text Box

Uses a masked definition to distinguish between a valid

and invalid user input.

[The Windows Forms SoundPlayer class

enables you to easily include sounds in your

applications.

Tell about the [DLLImport (“winmm.dll”)] importation to play .mp3 files. ]

Ø Sound Player Class

The SoundPlayer class enables you to play sounds file in .wav format and enables you to load or play sounds asynchronously.

Ø Table Layout Panel

ú The TableTayOut panel control arranges its contents in a grid. Because the layout is performed both at design time and run time, it can change dynamically as the application

environment changes.

For example, clicking

an application’s .exe file from within the

Windows shell causes the shell to load the

Common language runtime (CLR) and call a

Well-known entry point within that .exe file’s

Assembly

. For example, the manifest contains the security requirements of the application, which enables the user to decide whether to allow the application to execute before downloading the code. The manifest also contains information about the application dependencies.

Thanks !

–Nikhil Kumar

Share SocialTwist Tell-a-Friend 

AdRotator Control in ASP.NET ?

June 28th, 2009

AdRotator Control in ASP.NET

Hi!

Here i will show you step by step procedure how to use

AdRotator Control in ASP.NET in visual studio 2005 / 2008

The use of AdRotator performs a very important role in Web sites

by AdRotator control linked pictures can be show and will change on

refreshing or by timing…

__________________________________________________

Here I am using Visual Studio 2008 but there is no condition you can use Visual Studio 2005 also.

So follow these steps to create State Implementation

The Steps are:

1- Start -> All Programs -> Visual Studio 2005 or Visual Studio 2008

Now The Visual Studio will Open like this:-

2- Now go to File Menu -> New -> Web Site

When you will click on the New Web Site a new form will open like this:-

3- Under Visual Studio Installed Template-> Choose ASP.NET WEB SITE -> Choose File System from the location combo box -> Set the path by the browse button - > Choose the language from the Language ComboBox (Visual C# , Visual Basic , J #)

Choose Visual C#

4 - Click on the OK Button:-

Now you will see a new from like this :-

First you have to learn XML and HTML to work with ASP .NET_

I have used <!– text –> to make the text as comment this is the way to make comment in this code …

This is the Source Code window and in this page you will se this code…

<%@ Page Language=”C#” AutoEventWireup=”true”  CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Type your webpage title here</title>  <!– Here you can specify your page title in between title tag
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<!– In between div tags you can manage your web controls like buttons, labels, picture

Box, ImageMap etc –>


</div>
</form>
</body>
</html>

See here is a tab named Design in the bottom of this page

5- Click on this tab and you will see a blank web page where you can drag any control from the toolbox (which is in the left side of this window)

Open Web.config file and write true in place of false, See

<compilation debug=”true”>

6- Drag a AdRotator Control in the design window or in the source window…

(If you are not able to see the AdRotator control in Toolbox then just type this code

<asp:AdRotator ID=”AdRotator1” runat=”server” DataSourceID=”XMLDataSource1”/>

7-Now the source window should be look like this :

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head runat=”server”>

<title>AdRotator Control Example</title>

</head>

<body>

<br />

<asp:AdRotator ID=”AdRotator2″ runat=”server” DataSourceID=”XmlDataSource1″ />

8- Now go to solution explorer and right click on the web site and choose Add New Item

and add a .xml extension file .

9- Now type this code in the .xml extension file

First of all you have to paste three images named (google.jpg,yahoo.jpg,msn.jpg) in App_Data folder which is in solution explorer…

<Advertisements>

<Ad>

<ImageUrl>google.jpg</ImageUrl>

<NavigateUrl>http://www.google.com</NavigateUrl>

<AlternateText>Visit Google.com</AlternateText>

<Impressions>80</Impressions>

<Keyword>search</Keyword>

</Ad>

<Ad>

<ImageUrl>msn.jpg</ImageUrl>

<NavigateUrl>http://www.msn.com</NavigateUrl>

<AlternateText>

Visit MSN.com

</AlternateText>

<Impressions>80</Impressions>

<Keyword>MSN</Keyword>

</Ad>

<Ad>

<ImageUrl>yahoo.jpg</ImageUrl>

<NavigateUrl>http://www.yahoo.com</NavigateUrl>

<AlternateText>

Visit yahoo.com

</AlternateText>

<Impressions>80</Impressions>

<Keyword>yahoo</Keyword>

</Ad>

</Advertisements>

10 - Now run your web site by Ctrl + F5

11- Refresh your web page…

OUT PUT

10-When you refresh your web page the picture will change with the link which you have given in ImageUrl.

11- Close web browser

12-Close visual studio

Thanks!

Share SocialTwist Tell-a-Friend 

70-536 Microsoft .NET Framework Application Development Foundation

June 21st, 2009

Q11: You need to create a dynamic assembly named MyAssembly. You also

need to save the assembly to disk. Which code segment should you use?

 

A. AssemblyName myAssemblyName = new AssemblyName();

myAssemblyName.Name = “MyAssembly”;

AssemblyBuilder myAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly

(myAssemblyName, AssemblyBuilderAccess.Run);

myAssemblyBuilder.Save(”MyAssembly.dll”);

 

B. AssemblyName myAssemblyName = new AssemblyName();

myAssemblyName.Name = “MyAssembly”;

AssemblyBuilder myAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly

(myAssemblyName, AssemblyBulderAccess.Save);

myAssemblyBuilder.Save(”MyAssembly.dll”);

 

C. AssemblyName myAssemblyName = new AssemblyName();

AssemblyBuilder myAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly

(myAssemblyName, AssemblyBuilderAccess.RunAndSave);

myAssemblyBuilder.Save(”MyAssembly.dll”);

 

D. AssemblyName myAssemblyName = new AssemblyName(”MyAssembly”);

AssemblyBuilder myAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly

(myAssemblyName, AssemblyBuilderAccess.Save);

myAssemblyBuilder.Save(”c:\\MyAssembly.dll”);

 

Answer: B

Q12: You need to call an unmanaged function from your managed code by

using platform invoke services. What should you do?

 

A. Create a class to hold DLL functions and then create prototype methods by using managed code.

 

B. Register your assembly by using COM and then reference your managed code from COM.

 

C. Export a type library for your managed code.

 

D. Import a type library as an assembly and then create instances of COM object.

 

Answer: A

 

 

Q13: You are loading a new assembly into an application. You need to

override the default evidence for the assembly. You require the common

language runtime (CLR) to grant the assembly a permission set, as if the

assembly were loaded from the local intranet zone. You need to build the

evidence collection. Which code segment should you use?

 

A. Evidence evidence = new Evidence(Assembly.GetExecutingAssembly().Evidence);

 

B. Evidence evidence = new Evidence();

evidence.AddAssembly(new Zone(SecurityZone.Intranet));

 

C. Evidence evidence = new Evidence();

evidence.AddHost(new Zone(SecurityZone.Intranet));

 

D. Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);

 

 

Answer: C

 

Q14: You write the following code to implement the CompanyClass.MyMethod

function.

 

public class CompanyClass {

public int MyMethod(int arg) {

return arg; }}

 

You need to call the CompanyClass.MyMethod function dynamically from an

unrelated class in your assembly. Which code segment should you use?

 

A. CompanyClass myClass = new CompanyClass();

Type t = typeof(CompanyClass);

MethodInfo m = t.GetMethod(”MyMethod”);

int i = (int)m.Invoke(this, new object[] { 1 });

 

B. CompanyClass myClass = new CompanyClass();

Type t = typeof(CompanyClass);

MethodInfo m = t.GetMethod(”MyMethod”);

int i = (int) m.Invoke(myClass, new object[] { 1 });

 

C. CompanyClass myClass = new CompanyClass();

Type t = typeof(CompanyClass);

MethodInfo m = t.GetMethod(”CompanyClass.MyMethod”);

int i = (int)m.Invoke(myClass, new object[] { 1 });

 

 

D. Type t = Type.GetType(”CompanyClass”);

MethodInfo m = t.GetMethod(”MyMethod”);

int i = (int)m.Invoke(this, new object[] { 1 });

 

 

Answer: B

 

Implementing globalization, drawing, and text manipulation functionality in a .NET Framework application

 

 

Q1: You are developing an application for a client residing in Hong Kong.

You need to display negative currency values by using a minus sign. Which

code segment should you use?

 

A.   NumberFormatInfo culture = new CultureInfo(”zh-HK”).NumberFormat;

culture.NumberNegativePattern = 1;

return numberToPrint.ToString(”C”, culture);

 

B.   NumberFormatInfo culture = new CultureInfo(”zh-HK”).NumberFormat;

culture.CurrencyNegativePattern = 1;

return numberToPrint.ToString(”C”, culture);

 

C.   CultureInfo culture = new CultureInfo(”zh-HK”);

return numberToPrint.ToString(”-(0)”, culture);

 

D.   CultureInfo culture = new CultureInfo(”zh-HK”);

return numberToPrint.ToString(”()”, culture);

 

 

Answer: B

 

Q2: You are writing a method that accepts a string parameter named

message. Your method must break the message parameter into individual

lines of text and pass each line to a second method named Process.

Which code segment should you use?

 

A. StringReader reader = new StringReader(message);

Process(reader.ReadToEnd());

reader.Close();

 

B. StringReader reader = new StringReader(message);

while (reader.Peek() != -1) {

string line = reader.Read().ToString();

Process(line);}

reader.Close();

 

C. StringReader reader = new StringReader(message);

Process(reader.ToString());

reader.Close();

 

D. StringReader reader = new StringReader(message);

while (reader.Peek() != -1) {

Process(reader.ReadLine());}

reader.Close();

 

Answer: D

 

Q3: You are developing a fiscal report for a customer. Your customer has

a main office in the United States and a satellite office in Mexico.

You need to ensure that when users in the satellite office generate the

report, the current date is displayed in Mexican Spanish format. Which code

segment should you use?

 

A. DateTimeFormatInfo dtfi = new CultureInfo(”es-MX”, false).DateTimeFormat;

DateTime dt = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);

string dateString = dt.ToString(dtfi.LongDatePattern);

 

B. Calendar cal = new CultureInfo(”es-MX”, false).Calendar;

DateTime dt = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);

Strong DateString = dt.ToString();

 

C. string dateString = DateTimeFormatInfo.CurrentInfo

GetMonthName(DateTime.Today.Month);

 

D. string dateString = DateTime.Today.Month.ToString(”es-MX”);

 

 

Answer: A

 

Q4: You create an application that stores information about your

customers who reside in various regions. You are developing internal

utilities for this application. You need to gather regional information about

your customers in Canada. Which code segment should you use?

 

A. foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.SpecificCultures))

{

// Output the region information…

}

 

B. CultureInfo cultureInfo = new CultureInfo(”CA”);

 // Output the region information

 

 

C. RegionInfo regionInfo = new RegionInfo(”CA”);

// Output the region information

 

D. RegionInfo regionInfo = new RegionInfo(”");

if(regionInfo.Name == “CA”) {

// Output the region information

}

 

Answer: C

 

Q5: You need to generate a report that lists language codes and region

codes. Which code segment should you use?

 

A. foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) {

// Output the culture information…

}

 

B. CultureInfo culture = new CultureInfo(”");

CultureTypes types = culture.Culture Types;

// Output the culture information…

 

C. foreach (CultureInfo culture in

CultureInfo.GetCultures(CultureTypes.NeutralCultures)) {

// Output the culture information…

}

 

D. foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.ReplacementCultures)) {

// Output the culture information…

}

 

Answer: A

 

Q6: You are developing a method that searches a string for a substring.

The method will be localized to Italy.

Your method accepts the following parameters: The string to be searched,

which is named searchListThe string for which to search, which is named

searchValue You need to write the code. Which code segment should you

use?

 

A. return searchList.IndexOf(searchValue);

 

B. CompareInfo comparer = new CultureInfo(”it-IT”).CompareInfo;

return comparer.Compare(searchList, searchValue);

 

C. CultureInfo Comparer = new CultureInfo(”it-IT”);

if(searchList.IndexOf(searchValue) > 0) {

return true;

} else {

return false;}

 

D. CompareInfo comparer = new CultureInfo(”it-IT”).CompareInfo;

if (comparer.IndexOf(searchList, searchValue) > 0) {

return true;}

else {

return false;}

 

Answer: D

 

Q7: You are developing a utility screen for a new client application. The

utility screen displays a thermometer that conveys the current status of

processes being carried out by the application. You need to draw a

rectangle on the screen to serve as the background of the thermometer as

shown in the exhibit. The rectangle must be filled with gradient shading.

Which code segment should you choose?

Exhibit:

 

 

 

A. Rectangle rectangle = new Rectangle(10, 10, 450, 25);

LinearGradientBrush rectangleBrush = new LinearGradientBrush(rectangle, Color.AliceBlue, Color.CornflowerBlue, LinearGradientMode.ForwardDiagonal);

Pen rectanglePen = new Pen(rectangleBrush);

Graphics g = this.CreateGraphics();

g.DrawRectangle(rectanglePen, rectangle);

 

B. Rectangle rectangle = new Rectangle(10, 10, 450, 25);

LinearGradientBrush rectangleBrush = new LinearGradientBrush(rectangle, Color.AliceBlue, Color.CornflowerBlue, LinearGradientMode.ForwardDiagonal);

Pen rectanglePen = new Pen(rectangleBrush);

Graphics g = this.CreateGraphics();

g.FillRectangle(rectangleBrush, rectangle);

 

 

C. RectangleF rectangle = new RectangleF(10f, 10f, 450f, 25f);

Point[] points = new Point[] {new Point(0, 0), new Point(110, 145)};

LinearGradientBrush rectangelBrush = new LinearGradientBrush(rectangle, Color.AliceBlue, Color.CornflowerBlue, LinearGradientMode.ForwardDiagonal);

Pen rectanglePen = new Pen(rectangleBrush);

Graphics g = this.CreateGraphics();

g.DrawPolygon(rectanglePen, points);

 

D. RectangleF rectangle = new RectangleF(10f, 10f, 450f, 25f);

SolidBrush rectangleBrush = new SolidBrush(Color.AliceBlue);

Pen rectanglePen = new Pen(rectangleBrush);

Graphics g = this.CreateGraphics();

g.DrawRectangle(rectangleBrush, rectangle);

 

 

Answer: B

 

 

–Nikhil Kumar

Share SocialTwist Tell-a-Friend 

Microsoft .NET Framework 2.0 Application Development Foundation

June 21st, 2009

Microsoft .NET Framework 2.0 Applicatin Development Foundation Questions

Microsoft Certification Exams Faqs…

100 % changes to come every year …

Q7: You use Reflection to obtain information about a method named

MyMethod. You need to ascertain whether MyMethod is accessible to a

derived class. What should you do?

A. Call the IsAssembly property of the MethodInfo class.

 

B. Call the IsVirtual property of the MethodInfo class.

 

C. Call the IsStatic property of the MethodInfo class.

 

D. Call the IsFamily property of the MethodInfo class.

 

 

Answer: D

 

Q8: You write the following code segment to call a function from the

Win32 Application Programming Interface (API) by using platform invoke.

 

string personName = “N?el”;

string msg = “Welcome” + personName + “to club”!”;

bool rc = User32API.MessageBox(0, msg, personName, 0);

 

You need to define a method prototype that can best marshal the string

data. Which code segment should you use?

 

A. [DllImport("user32", CharSet = CharSet.Ansi)]

public static extern bool MessageBox(int hWnd, string text, string caption, uint type);

}

 

B. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet = CharSet.Ansi)]

public static extern bool MessageBox(int hWnd,

[MarshalAs(UnmanagedType.LPWStr)]string text,

[MarshalAs(UnmanagedType.LPWStr)]string caption,

uint type);

}

C. [DllImport("user32", CharSet = CharSet.Unicode)]

public static extern bool MessageBox(int hWnd, string text, string caption, uint type);

}

 

D. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet = CharSet.Unicode)]

public static extern bool MessageBox(int hWnd,

[MarshalAs(UnmanagedType.LPWStr)]string text,

[MarshalAs(UnmanagedType.LPWStr)]string caption,

uint type);

}

 

Answer: C

 

Q9: You need to create a class definition that is interoperable along with

COM. You need to ensure that COM applications can create instances of the

class and can call the GetAddress method. Which code segment should you

use?

 

A. public class Customer {

string addressString;

public Customer(string address) { addressString = address; }

public string GetAddress() { return addressString; }}

 

B. public class Customer {

static string addressString;

public Customer() { }

public static string GetAddress() { return addressString; }}

 

C. public class Customer {

string addressString;

public Customer() { }

public string GetAddress() { return addressString; }}

 

D. public class Customer {

string addressString;

public Customer() { }

internal string GetAddress() { return addressString; }}

 

Answer: C

 

Q10: You write the following code to call a function from the Win32

Application Programming Interface (API) by using platform invoke.

 

int rc = MessageBox(hWnd, text, caption, type);

 

You need to define a methon prototype. Which code segment should you

use?

 

A. [DllImport("user32")]

public static extern int MessageBox(int hWnd, String text, String caption, uint type);

 

B. [DllImport("user32")]

public static extern int MessageBoxA(int hWnd, String text, String caption, uint type);

 

C. [DllImport("user32")]

public static extern int Win32API_User32_MessageBox(int hWnd, String text, String caption, uint type);

 

D. [DllImport(@"C:\WINDOWS\system32\user32.dll")]

public static extern int MessageBox(int hWnd, String text, String caption, uint type);

 

Answer: A

 

Q11: You need to create a dynamic assembly named MyAssembly. You also

need to save the assembly to disk. Which code segment should you use?

 

A. AssemblyName myAssemblyName = new AssemblyName();

myAssemblyName.Name = “MyAssembly”;

AssemblyBuilder myAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly

(myAssemblyName, AssemblyBuilderAccess.Run);

myAssemblyBuilder.Save(”MyAssembly.dll”);

 

B. AssemblyName myAssemblyName = new AssemblyName();

myAssemblyName.Name = “MyAssembly”;

AssemblyBuilder myAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly

(myAssemblyName, AssemblyBulderAccess.Save);

myAssemblyBuilder.Save(”MyAssembly.dll”);

 

C. AssemblyName myAssemblyName = new AssemblyName();

AssemblyBuilder myAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly

(myAssemblyName, AssemblyBuilderAccess.RunAndSave);

myAssemblyBuilder.Save(”MyAssembly.dll”);

 

D. AssemblyName myAssemblyName = new AssemblyName(”MyAssembly”);

AssemblyBuilder myAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly

(myAssemblyName, AssemblyBuilderAccess.Save);

myAssemblyBuilder.Save(”c:\\MyAssembly.dll”);

 

Answer: B

 

–Nikhil Kumar

Share SocialTwist Tell-a-Friend 

Microsoft .NET Framework 2.0 Application Development Foundation

June 21st, 2009


Q2: You create an application to send a message by e-mail. An SMTP

server is available on the local subnet. The SMTP server is named

smtp.Company.com. To test the application, you use a source address,

me@Company.com, and a target address, you@Company.com.

You need to transmit the e-mail message. Which code segment should you

use?

 

A. MailAddress addrFrom = new MailAddress(”me@Company.com”, “Me”);

MailAddress addrTo         = new MailAddress(”you@Company.com”, “You”);

MailMessage message      = new MailMessage(addrFrom, addrTo);

message.Subject             = “Greetings!”;

message.Body                 = “Test”;

message.Dispose();

 

B. string strSmtpClient     = “mstp.Company.com”;

string strFrom                 = “me@Company.com”;

string strTo                     = “you@Company.com”;

string strSubject              = “Greetings!”;

string strBody                  = “Test”;

MailMessage msg             = new MailMessage(strFrom, strTo, strSubject, strSmtpClient);

C. MailAddress addrFrom          = new MailAddress(”me@Company.com”);

MailAddress addrTo                  = new MailAddress(”you@Company.com”);

MailMessage message               = new MailMessage(addrFrom, addrTo);

message.Subject                      = “Greetings!”;

message.Body                          = “Test”;

SmtpClient client                      = new SmtpClient(”smtp.Company.com”);

client.Send(message);

 

D. MailAddress addrFrom           = new MailAddress(”me@Company.com”, “Me”);

MailAddress addrTo                   = new MailAddress(”you@Company.com”, “You”);

MailMessage message                = new MailMessage(addrFrom, addrTo);

message.Subject                       = “Greetings!”;

message.Body                           = “Test”;

SocketInformation info               = new SocketInformation();

Socket client                             = new Socket(info);

System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

byte[] msgBytes                        = enc.GetBytes(message.ToString());

client.Send(msgBytes);

 

 

Answer: C

 

Q3: You need to write a code segment that will create a common

language runtime (CLR) unit of isolation within an application. Which code

segment should you use?

 

A. AppDomainSetup mySetup = AppDomain.CurrentDomain.SetupInformation;

mySetup.ShadowCopyFiles = “true”;

 

B. System.Diagnostics.Process myProcess;

myProcess = new System.Diagnostics.Process();

 

C. AppDomain domain;

domain = AppDomain.CreateDomain(”CompanyDomain”):

 

D. System.ComponentModel.Component myComponent;

myComponent = new System.ComponentModel.Component();

 

 

Answer: C

 

 

Q4: You are developing an application that dynamically loads assemblies

from an application directory.

You need to write a code segment that loads an assembly named

Company1.dll into the current application domain. Which code segment

should you use?

 

A. AppDomain domain = AppDomain.CurrentDomain;

string myPath = Path.Combine(domain.BaseDirectory, “Company1.dll”);

Assembly asm = Assembly.LoadFrom(myPath);

 

B. AppDomain domain = AppDomain.CurrentDomain;

string myPath = Path.Combine(domain.BaseDirectory, “Company1.dll”);

Assembly asm = Assembly.Load(myPath);

 

C. AppDomain domain = AppDomain.CurrentDomain;

string myPath = Path.Combine(domain.DynamicDirectory, “Company1.dll”);

Assembly asm = AppDomain.CurrentDomain.Load(myPath);

 

D. AppDomain domain = AppDomain.CurrentDomain;

Assembly asm = domain.GetData(”Company1.dll”);

 

Answer: A

 

Q5: You are creating a class that uses unmanaged resources. This class

maintains references to managed resources on other objects. You need to

ensure that users of this class can explicitly release resources when the

class instance ceases to be needed. Which three actions should you

perform? (Each correct answer presents part of the solution. Choose

three.)

 

A. Define the class such that it inherits from the WeakReference class.

 

B. Define the class such that it implements the IDisposable interface.

 

C. Create a class destructor that calls methods on other objects to release the managed resources.

 

D. Create a class destructor that releases the unmanaged resources.

 

E. Create a Dispose method that calls System.GC.Collect to force garbage collection.

 

F. Create a Dispose method that releases unmanaged resources and calls methods on other objects to release the managed resources.

 

Answer: B, D, F

 

Q6: You write a class named Employee that includes the following code

segment.

 

public class Employee

{

string employeeId, employeeName, jobTitleName;

 

public string GetName()

{

                return employeeName;

}

 

public string GetTitle()

{

                return jobTitleName;

}

 

}

 

You need to expose this class to COM in a type library. The COM interface must

also facilitate forward-compatibility across new versions of the Employee class.

You need to choose a method for generating the COM interface. What should you

do?

 

 

A. Add the following attribute to the class definition.

[ClassInterface(ClassInterfaceType.None)]

public class Employee {

 

B. Add the following attribute to the class definition.

[ClassInterface(ClassInterfaceType.AutoDual)]

public class Employee {

 

C. Add the following attribute to the class definition.

[ComVisible(true)]

public class Employee {

 

D. Define an interface for the class and add the following attribute to the class

definition.

[ClassInterface(ClassInterfaceType.None)]

public class Employee : IEmployee {

 

 

Answer: D

–Nikhil Kumar

Share SocialTwist Tell-a-Friend 

Microsoft .NET Framework 2.0 Application Development Foundation

June 21st, 2009

These are not just questions these are very much important questions which are sure to come in microsoft certification exam, These are questions are taken from the faculties, students and many more talented persons from microsoft and niit and other places…

so just learn these questions to get your certificate in your favour …

Q11: You are developing a method to decrypt data that was encrypted

with the Triple DES Algorithm. The method accepts the following

parameters:

         The byte array to be decrypted, which is named cipherMessage

         The key, which is named key

         An initialization vector, which is named iv

You need to decrypt the message by using the TripleDES class and place

the result in a string. Which code segment should you use?

A. TripleDES des = new TripleDESCryptoServiceProvider();

des.BlockSize = cipherMessage.Length;

ICryptoTransform crypto = des.CreateDecryptor(key, iv);

MemoryStream cipherStream = new MemoryStream(cipherMessage);

CryptoStream cryptoStream = new CryptoStream( cipherStream, crypto, CryptoStreamMode.Read);

string message;

message = new StreamReader(cryptoStream).ReadToEnd();

 

B. TripleDES des = new TripleDESCryptoServiceProvider();

des.FeedbackSize = cipherMessage.Length;

ICryptoTransform crypto = des.CreateDecryptor(key, iv);

MemoryStream cipherStream = new MemoryStream(cipherMessage);

CryptoStream cryptoStream = new CryptoStream(cipherStream, crypto, CryptoStreamMode.Read);

string message;

message = new StreamReader(cryptoStream).ReadToEnd();

C. TripleDES des = new TripleDESCryptoServiceProvider();

ICryptoTransform crypto = des.CreateDecryptor();

MemoryStream cipherStream = new MemoryStream(cipherMessage);

CryptoStream cryptoStream = new CryptoStream( cipherStream, crypto, CryptoStreamMode.Read);

string message;

message = new StreamReader(cryptoStream).ReadToEnd();

 

 

D. TripleDES des = new TripleDESCryptoServiceProvider();

ICryptoTransform crypto = des.CreateDecryptor(key, iv);

MemoryStream cipherStream = new MemoryStream(cipherMessage);

CryptoStream cryptoStream = new CryptoStream( cipherStream, crypto, CryptoStreamMode.Read);

string message;

message = new StreamReader(cryptoStream).ReadToEnd();

 

Answer: D

 

Q12: You are writing a method that returns an ArrayList named al. You

need to ensure that changes to the ArrayList are performed in a thread-

safe manner. Which code segment should you use?

 

A. ArrayList al = new ArrayList();

lock (al.SyncRoot){

return al;}

 

B. ArrayList al = new ArrayList();

lock (al.SyncRoot.GetType()){

return al;}

 

C. ArrayList al = new ArrayList();

Monitor.Enter(al);

Monitor.Exit(al);

return al;

 

D. ArrayList al = new ArrayList();

ArrayList sync_al = ArrayList.Synchronized(al);

return sync_al;

 

 

Answer: D

 

Q13: You create a method that runs by using the credentials of the end

user. You need to use Microsoft Windows groups to authorize the user. You

must add a code segment that identifies whether a user is in the local

group named Clerk. Which code segment should you use?

 

A. WindowsIdentity currentUser = WindowsIdentity.GetCurrent();

foreach(IdentityReference grp in currentUser.Groups) {

NTAccount grpAccount = ((NTAccount)grp.Translate(typeof(NTAccount)));

isAuthorized = grpAccount.Value.Equals(Environment.MachineName + @”\Clerk”);

if(isAuthorized)

break;}

 

B. WindowsPrincipal currentUser = (WindowsPrincipal)Thread.CurrentPrincipal;

isAuthorized = currentUser.IsInRole(”Clerk”);

 

C. GenericPrincipal currentUser = (GenericPrincipal)Thread.CurrentPrincipal;

isAuthorized = currentUser.IsInRole(”Clerk”);

 

D. WindowsPrincipal currentUser = (WindowsPrincipal)Thread.CurrentPrincipal;

isAuthorized = currentUser.IsInRole(Environment.MachineName);

 

 

Answer: B

 

Q14: You are writing code for user authentication and authorization. The

username, password, and roles are stored in your application data store.

You need to establish a user security context that will be used for

authorization checks such as IsInRole. You write the following code

segment to authorize the user.

if (!TestPassword(userName, password))

throw new Exception(”could not authenticate user”);

String[] userRolesArray = LookupUserRoles(userName);

You need to complete this code so that it establishes the user security

context. Which code segment should you use?

A. GenericIdentity ident = new GenericIdentity(userName);

GenericPrincipal currentUser = new GenericPrincipal(ident, userRolesArray);

Thread.CurrentPrincipal = currentUser;

B. WindowsIdentity ident = new WindowsIdentity(userName);

WindowsPrincipal currentUser = new WindowsPrincipal(ident);

Thread.CurrentPrincipal = currentUser;

C. NTAccount userNTName = new NTAccount(userName);

GenericIdentity ident = new GenericIdentity(userNTName.Value);

GenericPrincipal currentUser = new GenericPrincipal(ident, userRolesArray);

Thread.CurrentPrincipal = currentUser;

D. IntPtr token = IntPtr.Zero;

token = LogonUserUsingInterop(username, encryptedPassword);

WindowsImpersonationContext ctx = WindowsIdentity.Impersonate(token);

 

Answer: A

–Nikhil Kumar

Share SocialTwist Tell-a-Friend 

Microsoft .NET Framework 2.0 Application Development Foundation

June 21st, 2009

Q5: You are developing a class library. Portions of your code need to

access system environment variables.

You need to force a runtime SecurityException only when callers that are

higher in the call stack do not have the necessary permissions.

Which call method should you use?

 

A. set.Demand();

 

B. set.Assert();

 

C. set.PermitOnly();

 

D. set.Deny();

 

Answer: A

 

 

Q6: You are developing a method to hash data for later verification by

using the MD5 algorithm. The data is passed to your method as a byte array

named message. You need to compute the hash of the incoming parameter

by using MD5. You also need to place the result into a byte array.

Which code segment should you use?

 

A. HashAlgorithm algo = HashAlgorithm.Create(”MD5″);

byte[] hash = algo.ComputeHash(message);

 

B. HashAlgorithm algo = HashAlgorithm.Create(”MD5″);

byte[] hash = BitConverter.GetBytes(algo.GetHashCode());

 

C. HashAlgorithm algo;

algo = HashAlgorithm.Create(message.ToString());

byte[] hash = algo.Hash;

 

D. HashAlgorithm algo = HashAlgorithm.Create(”MD5″);

byte[] hash = null;

algo.TransformBlock(message, 0, message.Length, hash, 0);

 

 

Answer: A

 

Q7: You are changing the security settings of a file named MyData.xml.

You need to preserve the existing inherited access rules. You also need to

prevent the access rules from inheriting changes in the future.

Which code segment should you use?

 

A. FileSecurity security = new FileSecurity(”mydata.xml”, AccessControlSections.All);

security.SetAccessRuleProtection(true, true);

File.SetAccessControl(”mydata.xml”, security);

 

B. FileSecurity security = new FileSecurity();

security.SetAccessRuleProtection(true, true);

File.SetAccessControl(”mydata.xml”, security);

 

C. FileSecurity security = File.GetAccessControl(”mydata.xml”);

security.SetAccessRuleProtection(true, true);

 

D. FileSecurity security = File.GetAccessControl(”mydata.xml”);

security.SetAuditRuleProtection(true, true);

File.SetAccessControl(”mydata.xml”, security);

 

 

Answer: A

 

Q8: You are developing a server application that will transmit sensitive

information on a network. You create an X509Certificate object named

certificate and a TcpClient object named client. You need to create an

SslStream to communicate by using the Transport Layer Security 1.0

protocol. Which code segment should you use?

 

A. SslStream ssl = new SslStream(client.GetStream());

ssl.AuthenticateAsServer(certificate, false, SslProtocols.None, true);

 

B. SslStream ssl = new SslStream(client.GetStream());

ssl.AuthenticateAsServer(certificate, false, SslProtocols.Ssl3, true);

 

C. SslStream ssl = new slStream(client.GetStream());

ssl.AuthenticateAsServer(certificate, false, SslProtocols.Ssl2, true);

 

D. SslStream ssl = new SslStream(client.GetStream());

ssl.AuthenticateAsServer(certificate, false, SslProtocols.Tls, true);

 

 

Answer: D

 

Q9: You are developing a method to encrypt sensitive data with the Data

Encryption Standard (DES) algorithm. Your method accepts the following

parameters:

         The byte array to be encrypted, which is named message.

         An encryption key, which is named key

         An initialization vector, which is named iv

 

You need to encrypt the data. You also need to write the encrypted data to

a MemoryStream object. Which code segment should you use?

 

A. DES des = new DESCryptoServiceProvider();

des.BlockSize = message.Length;

ICryptoTransform crypto = des.CreateEncryptor(key, iv);

MemoryStream cipherStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(cipherStream, crypto, CryptoStreamMode.Write);

cryptoStream.Write(message, 0, message.Length);

 

B. DES des = new DESCryptoServiceProvider();

ICryptoTransform crypto = des.CreateDecryptor(key, iv);

MemoryStream cipherStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(cipherStream, crypto, CryptoStreamMode.Write);

cryptoStream.Write(message, 0, message.Length);

 

C. DES des = new DESCryptoServiceProvider();

ICryptoTransform crypto = des.CreateEncryptor();

MemoryStream cipherStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(cipherStream, crypto, CryptoStreamMode.Write);

cryptoStream.Write(message, 0, message.Length);

 

D. DES des = new DESCryptoServiceProvider();

ICryptoTransform crypto = des.CreateEncryptor(key, iv);

MemoryStream cipherStream = new MemoryStream();

CryptoStream cryptoStream = new CryptoStream(cipherStream, crypto, CryptoStreamMode.Write);

cryptoStream.Write(message, 0, message.Length);

 

 

Answer: D

 

Q10: You are creating a new security policy for an application domain.

You write the following lines of code.

 

PolicyLevel policy = PolicyLevel.CreateAppDomainLevel();

PolicyStatement noTrustStatement = new PolicyStatement(

policy.GetNamedPermissionSet(”Nothing”));

PolicyStatement fullTrustStatement = new PolicyStatement(

policy.GetNamedPermissionSet(”FullTrust”));

 

You need to arrange code groups for the policy so that loaded assemblies

default to the Nothing permission set. If the assembly originates from a

trusted zone, the security policy must grant the assembly the FullTrust

permission set. Which code segment should you use?

 

A. CodeGroup group1 = new FirstMatchCodeGroup(

new ZoneMembershipCondition(SecurityZone.Trusted), fullTrustStatement);

CodeGroup group2 = new UnionCodegroup(new AllMembershipCondition(),

noTrustStatement);

group1.AddChild(group2);

 

B. CodeGroup group1 = new FirstMatchCodeGroup(new AllMembershipCondition(),

noTrustStatement);

CodeGroup group2 = new UnionCodeGroup(new ZoneMembershipCondition(SecurityZone.Trusted), fullTrustStatement);

group1.AddChild(group2);

 

C. CodeGroup group = new UnionCodeGroup(new ZoneMembershipCondition(SecurityZone.Trusted), fullTrustStatement);

 

D. CodeGroup group = new FirstMatchCodeGroup( new AllMembershipCondition(), noTrustStatement);

 

 

Answer: B

– Nikhil Kumar

Share SocialTwist Tell-a-Friend 

Microsoft .NET Framework 2.0 Application Development Foundation

June 21st, 2009

Improving the security of the .NET Framework applications by using the .NET Framework 2.0 security features

 

Q1: You are developing a class library that will open the network socket

connections to computers on the network. You will deploy the class library

to the global assembly cache and grant it full trust.

You write the following code to ensure usage of the socket connections.

 

SocketPermission permission = new SocketPermission(PermissionState.Unrestricted);

permission.Assert();

 

Some of the applications that use the class library might not have the

necessary permissions to open the network socket connections.

You need to cancel the assertion.

Which code segment should you use?

A. CodeAccessPermission.RevertAssert();

B. CodeAccessPermission.RevertDeny();

C. permission.Deny();

D. permission.PermitOnly();

Answer: A

 

Explanation:

CodeAccessPermission.RevertAssert causes any previous Assert for the current frame to be removed and no longer in effect.

CodeAccessPermission.RevertDeny causes any previous Deny for the current frame to be removed and no longer in effect.

SocketPermission.Deny method prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.

SocketPermission.PermitOnly Prevents callers higher in the call stack from using the code that calls this method to access all resources except for the resource specified by the current instance.

 

Q2: You are developing an application that will use custom authentication

and role-based security. You need to write a code segment to make the

runtime assign an unauthenticated principal object to each running thread.

Which code segment should you use?

 

A. AppDomain domain = AppDomain.CurrentDomain;

domain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

 

B. AppDomain domain = AppDomain.CurrentDomain;

domain.SetThreadPrincipal(new WindowsPrincipal(null));

 

C. AppDomain domain = AppDomain.CurrentDomain;

domain.SetAppDomainPolicy(PolicyLevel.CreateAppDomainLevel());

 

D. AppDomain domain = AppDomain.CurrentDomain;

domain.SetPrincipalPolicy(PrincipalPolicy.UnauthenticatedPrincipal);

 

 

Answer: D

Explanation: PrincipalPolicy.UnauthenticatedPrincipal represents principal and identity objects for the unauthenticated entity should be created. An unauthenticated entity has Name set to the empty string (”") and IsAuthenticated set to false.

 

Q3: You work as a developer at Company.com. You are creating an

assembly named Company1. Company1 contains a public method.

The global cache contains a second assembly named Company2.

You must ensure that the public method is only called from Company2.

Which permission class should you use?

 

 

A. GacIdentityPermission

 

B. PublisherIdentityPermission

 

C. DataProtectionPermission

 

D. StrongNameIdentityPermission

 

Answer: D

Explanation:

GacIdentityPermission defines the identity permission for files originating in the global assembly cache. Files are either in the global assembly cache, or they are not. There are no variations to the permission granted, so all GacIdentityPermission objects are equal.

PublisherIdentityPermission represents the identity of a software publisher.

DataProtectionPermission controls the ability to access encrypted data and memory.

StrongNameIdentityPermission defines the identity permission for strong names.

 

Q4: You are developing a method to hash data with the Secure Hash

Algorithm. The data is passed to your method as a byte array named

message. You need to compute the hash of the incoming parameter by

using SHA1. You also need to place the result into a byte array named

hash. Which code segment should you use?

 

A. SHA1 sha = new SHA1CryptoServiceProvider();

byte[] hash = null;

sha.TransformBlock(message, 0, message.Length, hash, 0);

 

B. SHA1 sha = new SHA1CryptoServiceProvider();

byte[] hash = BitConverter.GetBytes(sha.GetHashCode());

 

C. SHA1 sha = new SHA1CryptoServiceProvider();

byte[] hash = sha.ComputeHash(message);

 

D. SHA1 sha = new SHA1CryptoServiceProvider();

sha.GetHashCode();

byte[] hash = sha.Hash;

 

 

Answer: C

–Nikhil Kumar

Share SocialTwist Tell-a-Friend