Awp Odd

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Q1)a) explain foreach loop wih suitable example e) Explain jagged array with an example.

}
The foreach statement is used to iterate through the items in a list. It operates on arrays or A jagged array is an array of arrays. You can declare a jagged array named scores of type 4. Copy Constructor
collections such as ArrayList, which can be found in System, collections namespace. The in as int [][] scores; A constructor that contains a parameter of same class type is called as copy constructor.
general form of foreach is, Declaring an array, does not create the array in memory. To create the above array C# does not provide a copy constructor. A copy constructor enables you to copy the data
forech(<type><itemname>in<list>) int [][] scores = new int [5][]; stored in the member variables of an object of the class into another new object means it
{ for (int i=0; i < scores.Length; i++ ) helps to copy data stored in one object into another new object of the same instance.
code { scores[i] = new int[4]; } class test
} You can initialize a jagged array as – {
The type is the type of item contained in the list. Eg – if the type of list is int[], then the type Int [][] scores = new int [2][]{new int []{92,93,94},new int []{85,66,87,88}}; public test(test t1) //Copy constructor
would be int. The itemname is an identifier that you can choose, which could be anythingbut Where, score is an array of integers – scores [0] is an array of 3 integers and score[1] is an {
should e meaningful. While iterating through the items of a list with a foreach loop, the list array of 4 integers length =
is read only. This means you cant change the value of any items in list within a foreach loop. t1.length;
Example- f) What is .NET Framework? Explain its architecture in brief. breadth =
using System; t1.breadth;
class ExamplefForEach }
{ }
public static void main() 5. Static Constructor
{ Static constructor should be parameter less means it should not contain any input
string[] str={“Sanjeev”,”Rakesh”,”Sagar”}; parameter. Program will not execute if static constructor is having any input parameter.
foreach(string s in str) Static constructor can be invoked once for any number instances are created and it is
{ invoked only during the first initialization of instance. It is used to initialize static fields of
Console.Writeline(s); the class. Static constructor is created using a static keyword as shown below.
} static int x;
} static test()
} {
Output- Console.WriteLine("static cons ");
Sanjeev x = 10;//set the values for static member here
Rakesh }
Sagar
f)What are .NET languages? Explain various features of C# languages.
b)what is namespace? Describe the system namespace The Microsoft .Net Framework provides the necessary foundation for developing windows
A namespace is designed for providing a way to way to keep one set of names separate from as well as web applications. The unique feature of .NET is the multi-language support that
another. The class names declared in one namespace does not conflict with the same class it provides. To help create languages for the .NET Framework, Microsoft created the
declared in another. Following are the components of .Net Framework: Common Language Infrastructure specification (CLI). The CLI describes the features that
Define a Namespace= A namespace definition begins with the keyword namespace A. User and program Interface: each language must provide in order to use the .NET Framework and common language
followed by the namespace name as follows: • It specifies the type of application that can generated using .Net. runtime. The .NET platform supports many languages and the list is growing day by day.
Namespace namespace_name • We can create following: The C# compiler is considered to be the most efficient compiler in the .NET family
{ i. Console application: C# is object oriented programming language. It provides a lot of features that are given
//code declaration ⎯ These are the application where input and output are through below:-
} console command. 1. Simple :- C# is a simple language in the sense that it provides structured approach, rich
To call the namespace-enabled version of either function or variable, prepend the ⎯ There are no forms, no internet connectivity required. set of library functions, data types etc. Unsafe operations such as direct memory
namespace name as follows: ii. Windows application: manipulation are not allowed.
Namespace_name.item_name; ⎯ Here input and output are through windows form.

The initialization of a two-dimensional array at the time of declaration is done in the AdRotator
following manner. c)various file types used in asp.net • One use of the AdRotator is to show banner-style advertisements on a page, but you can
int[,] x={{1,2},{2,4},{5,6}}; use it anytime you want to vary an image randomly. • The basic purpose of the AdRotator
or is to provide a graphic on a page that is chosen randomly from a group of possible images.
int[,] x=new int[2,3]{ {1,2},{2,4},{5,6}}; • In other words, every time the page is requested, an image is selected at random and
displayed,which is the rotation indicated by the name AdRotator.
h) Give details about Type Conversion The Advertisement File
It is a process of converting value of one ty[e into another type. It is also know as type The AdRotator stores its list of image files in an XML file. This file uses the format shown
casting. here:
Type conversion are of two types: <Advertisements><Ad><ImageUrl>prosetech.jpg</ImageUrl><NavigateUrl>http://www.
I. Implicit type conversion: prosetech.com</NavigateUrl><AlternateText>ProseTech
⎯ It is automatically done by C# in type safe manner. ⎯ Conversion of lower type to higher Site</AlternateText><Impressions>10</Impressions><Keyword>Computer</Keyword>
type is done implicitly. ⎯ No casting required ⎯ No loss of precision. </Ad></Advertisements>
E.g. int x = 10; • To add more advertisements, you would create multiple <Ad> elements and place them
float y = x; // implicit all inside the root <Advertisements> element. • Each <Ad> element has a number of other
II. Explicit type conversion: important properties that configure the link, the image, and the frequency. • The actual
⎯ Here the casting operator/ conversion function is explicitly required to perform casting.⎯ AdRotator class provides a limited set of properties. • You specify both the appropriate
Conversion of higher type to lower type is done explicitly.⎯ There is loss of precision. advertisement file in the AdvertisementFile property and the type of window that the link
E.g. double p= 12.6; should follow (the Target window). • The target can name a specific frame, or it can use one
int x =(int)p; of the values.
C# provides many conversion function. They are: This is a fully configured AdRotator tag:
• ToBoolean= Converts a type to a Boolean where, possible. • ToByte= Converts type to a • <asp:AdRotator ID="Ads" runat="server“ AdvertisementFile="MainAds.xml“
byte. • ToChar= Converts a type to a single Unicode character, where possible. • Target=”_blank” KeywordFilter=”Computer” />
ToDetermine= converts a type (integer to string) to date-time structure. • ToDecimal=
Converts floating point or integer type to decimal. • ToDouble= Converts a type to a double f) What are .aspx files? Explain code behind class file in detail
type. • ToInt16= Converts a type to 16-bit integer. • ToInt32= Converts a type to 32-bit • An ASPX file is an Active Server Page Extended (ASPX) file, which is a webpage generated
integer. • ToInt64= Converts a type to 64-bit integer. • ToString= converts a type to string. by web servers running the Microsoft ASP.NET framework. • It contains one or more scripts
• ToSingle= Converts a type to small floating point number written in VBScript or C# code that are processed by the web server into HTML, which is
sent to the user's web browser. • ASPX pages are also called ".NET Web forms". • The
Q2)a) List and explain any four types of validation controls used in ASP.NET. program logic is written in a separate file called code behind file. • The code behind file has
1. RequiredFieldValidator Control the extension .aspx.cs. There is a code behind file associated with each page of a website. •
The RequiredFieldValidator control is simple validation control, which checks to see if the As the program logic is separated from user interface design code, this model is easy to
data is entered for the input control. We can have a RequiredFieldValidator control for each understand. • The code for the page is compiled into a separate class from which the .aspx
form element on which you wish to enforce Mandatory Field rule. file derives. Only server controls can interact with the code behind the page; not the HTML
The syntax of the control is as given: <asp:RequiredFieldValidator ID="rfvcandidate" controls. • In the code-behind file, we create a class (which can be any class derived from
runat="server" ErrorMessage="Please enter name !!" d)list controls in asp.net the Page class) that serves as the base class for the web page we create in the .aspx file. •
ControlToValidate="txtName"></asp:RequiredFieldValidator> Asp.net provides the following controls – This relationship between our class and the web page is established by a Page directive at
2. RangeValidator Control • dropdown list the top of the .aspx file. • When users point their browsers to the .ASPX page, the code-
The RangeValidator Server Control is another validator control, which checks to see if a behind class file runs and dynamically produces the output for the page. When the page is
• list box
control value is within a valid range. The attributes that are necessary to this control are: requested, the code-behind file is loaded and treated as an integral part of the page. • We
• radio button list
MaximumValue, MinimumValue, and Type. enable the ASP.NET code-behind feature by adding a couple of attributes, namely Inherits
• checkbox list
and Src, to the @Page directive - <%@ Page Language="C#" Inherits="MyBasePageClass"
• bulleted list Src="MyBasePage.cs" %> • The Inherits attribute contains the name of the code-behind

iv) Menu :- The ASP.NET Menu control allows us to develop both statically and dynamically master page to create a menu that applies to all pages. ➢ They give us fine-grained control This management technique basically makes use of the following:
displayed menus for our ASP.NET Web pages. We can configure the contents of the Menu over the layout of the final page by allowing us to control how the placeholder controls are a. View State: View State can be used to maintain the State at a page level. The term "Page
control directly in the control, or we can specify the contents by binding the control to a rendered. ➢ They provide an object model that allows us to customize the master page from Level" means that the information is being stored for a specific page and until that specific
data source. Without writing any code, we can control the appearance, orientation, and individual content pages page is active (i.e. the page which is being currently viewed by the user). Once the user is
content of an ASP.NET Menu control. re-directed or goes to some other page, the information stored in the View
Example –<asp:Menu ID="Menu1" runat="server"></asp:Menu> e) Describe session state variables in asp.net State gets lost. b. Hidden Fields: ASP.NET provides a server control called "Hidden Field"
• Session-state management is one of ASP.NET’s premiere features. • It allows us to store which can be used to store a value at a page level, which is similar to a View State. The value
Q3)a)what is Query string any type of data in memory on the server. • The information is protected, because it is never of the Hidden Field is sent along in the HTTP Form Collection along with the value of other
In web application, passing of data from one page to another is an essential part. By using transmitted to the client, and it’s uniquely bound to a specific session. • Session state is ideal controls. c. Query String: A Query String is a string which is appended to the end of the
QueryString, one can easily transmit data from one page to another. QueryStrings are for storing information such as the items in the current user’s shopping basket when the Page URL. It is very simple to use and can be used to send data across pages. It stores
simply the data that is appended to the end of a web page URL. The user can view the values user browses from one page to another. • ASP.NET tracks each session by using a unique information in a key - value pair. A "?" signature is used to append the key and value to the
which the QueryString holds without using special operations like ViewSource. identifier. • ASP.NET uses a proprietary algorithm to generate this value, thereby page URL. d. Cookies: ASP.Net provides another way of state management, which is by
Advantages- 1)it is very easy to use. Disadvanage- 1)it cannot be used to send and add space guaranteeing (statistically speaking) that the number is unique and it’s random. using Cookies. Cookies are one of the best ways of storing information. It is nothing but a
characters • When the client presents the session ID, ASP.NET looks up the corresponding session, text file which is stored on the client's machine. When the user sends a request to the server,
retrieves the objects we stored previously, and places them into a special collection so they the server creates a cookie and attaches a header and sends it back to the user along with
b) What is a theme? How does it work? can be accessed in our code. • The session state object is created from the HttpSessionState the response. The browser accepts the cookie and stores it at a specific location on the
A theme decides the look and feel of the website. It is a collection of files that define class, which defines a collection of session state items. • We can interact with session state client's machine. Even large sites like Gmail, Facebook, Yahoo use cookies. Server Side State
the looks of a page. It can include skin files, CSS files & images. by using the System.Web.SessionState.HttpSessionState class, which is provided in an Management. It is another way which ASP.NET provides to store the user's specific
Uses of Themes ASP.NET web page as the built-in Session object. • The syntax for adding items to the information or the state of the application on the server machine. It completely makes use
1. Since themes can contain CSS files, images and skins, you can change colors, fonts, collection and retrieving them is basically the same as for adding items to a page’s view of server resources (the server's memory) to store information.
positioning and images simply by applying the desired themes. 2. We can have as many state. This management technique basically makes use of the following,
themes as we want, and we can switch between them by setting a single attribute in the • Adding session state variables :- a. Application State: If the information that we want to be accessed or stored globally
web.config file or an individual aspx page. Also, we can switch between themes Session["session_variable_name"]=value; throughout the application, even if multiple users access the site or application at the same
programmatically. 3. Setting the themes programmatically, we are offering our users a Example :- time, then we can use an Application Object for such purposes. It stores information as a
quick and easy way to change the page to their likings. 4. Themes allow us to improve the Session["x"] ="Tata"; Dictionary Collection in key - value pairs. This value is accessible across the pages of the
usability of our site by giving users with vision problems the option to select a high contrast Session["y"] = "atat"; application / website. b. Session State: Session is one of the most common way which is
theme with a large font size. We define themes in a special App_Themes folder. Inside this The session variable can also be added using add() method. being used by developers to maintain the state of the application. The Session basically
folder is one or more subfolders named Theme1, Theme2 etc. that define the actual themes. Example : stores the values as a dictionary collection in key/value pairs. It completely utilizes server
The theme property is applied late in the page's life cycle, effectively overriding any string s1 = TextBox1.Text; resources to store the data. It is a secure way of storing data, since the data will never be
customization we may have for individual controls on our page. Session.Add("z", s1); passed to the client. For each and every user, a separate Session is created, and each and
There are 3 different options to apply themes to our website: • Retrieving Session Variables :- every Session has its Unique ID. This ID is being stored in the client's machine using cookies.
1. Setting the theme at the page level: The Theme attribute is added to the page directive of String variable=Session["session_variable_name"].ToString(); If there are multiple users who are accessing a web application, then for each user a
the page. <%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs" Example :- separate Session is created. If a single user logs in and logs out the Session is killed, then if
Inherits="Default"Theme="Theme1"%> string x = Session["z"].ToString(); the same user again logs into the application, then a new Session ID is being created for the
2. Setting the theme at the site level: to set the theme for the entire website we can set the same user.
theme in the web.config of the website. Open the web.config file and locate the <pages> f) Explain exception handling mechanism with proper syntax and example.
element and add the theme attribute to it: <pages theme="Theme1"> .... .... </pages> 3. • An exception is an event that interrupts normal program execution. • In other words, h) What is ViewState in ASP.NET? State its advantages and disadvantages.
Setting the theme programmatically at runtime: here the theme is set at runtime through when an error occurs in our application, the .NET Framework creates an exception object ViewState is one of the most import and useful client-side state management mechanism. It
coding. It should be applied earlier in the page's life cycle ie. Page_PreInit event should be that represents the problem. • We can catch this object by using an exception handler. If we can store the page value at the time of post back of your page. ASP.NET pages provide the
handled for setting the theme. The better option is to apply this to the Base page class of the fail to use an exception handler, our code will be aborted, and the user will see an error ViewState property as built-in structure for automatically storing values between requests
site as every page in the site inherits from this class. Page.Theme = Theme1; page. • If we catch the exception, we can notify the user, attempt to resolve the problem, or for the same page.
simply ignore the issue and allow our web page code to keep running. • There are two Example: Of you want to add one variable in ViewState
c) What are the three different ways to use styles on web pages? Explain various Hide Copy Code ViewState[“Var”] = Count;
data through ADO.NET. The data reader is also called a firehose cursor or forward read-only call WriteStartElement() and follow it up with a call to WriteAttributeString(), you are
cursor because it moves forward through the data. The data reader not only allows you to adding an attribute to that element. Similarly, if you use WriteString(), you insert text
move forward through each record of database, but it also enables you to parse the data content inside the current element, and if you use • WriteStartElement() again, you write
from each column. The DataReader class represents a data reader in ADO.NET. another element, nested inside the current element.
Similar to other ADO.NET objects, each data provider has a data reader class for example;
OleDbDataReader is the data reader class for OleDb data providers. Similarly, 5d. What is authorization? Explain adding authorization rules in web.config file.
SqlDataReader and ODBC DataReader are data reader classes for SQL and ODBC data Ans: • Authorization is the process of determining whether a user has sufficient permission
providers, respectively.The IDataReader interface defines the functionally of a data reader to perform a given action. • Once a user is authenticated, authorization is the process of
and works as the base class for all data provider-specific data reader classes such as determining whether that user has sufficient permission to perform a given action (such as
OleDataReader. SqlDataReader, and OdbcDataReader. Figure 5-36 shows some of the viewing a page or retrieving information from a database). • Windows imposes some
classes that implement IDbDataReader. authorization checks (for example, when you open a file), but your code will probably want
Code - to impose its own checks (for example, when a user performs a task in your web application
SqlCommand myCMD = new SqlCommand("SELECT CategoryID, CategoryName FROM such as submitting an order, assigning a project, or giving a promotion). • Authentication
Categories;" + "SELECT EmployeeID, LastName FROM Employees", nwindConn); and authorization are the cornerstones of a secure user-based site. • To control who can
nwindConn.Open(); and can’t access your website, you need to add access-control rules to the <authorization>
SqlDataReader myReader = myCMD.ExecuteReader(); section of your web.config file.
do { • WEB.CONFIG FILE
Console.WriteLine("\t{0}\t{1}", myReader.GetName(0), myReader.GetName(1)); <configuration>
while (myReader.Read()) Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myRea ...
der.GetString(1)); } <system.web>
while (myReader.NextResult()); ...
myReader.Close(); <authentication mode="Forms">
nwindConn.Close(); <forms loginUrl="~/Login.aspx" />
</authentication>
Q5)a) What do you mean by authentication? Explain its types. <authorization>
Authentication: <allow users="*" />
⎯ In ASP.NET there are many different types of authentication procedures for web </authorization>
applications. If you want to specify your own authentication methods then that also is </system.web>
possible. ⎯ The different authentication modes are accepted through settings that can be </configuration>
applied to the applications web.config file. ⎯ The web.config file is XML-bsed file which • The asterisk (*) is a wildcard character that explicitly permits all users to use the
allows changing of ASP.NET behavior easily. ⎯ ASP.NET provides three different application—even those who haven’t been authenticated. • The question mark (?) is a
authentication provides: o Windows o From o Passport wildcard character that matches all anonymous users. • By including following rule in
✓ Windows: It allows to authenticate user based on their windows accounts. This provider applications web.config file, you specify that anonymous users are not allowed.
uses IIS to perform the authentication and then asses the authenticated identity to your <authorization>
code. This is the default provides for ASP.NET. Syntax: <authencation mode= “windows”> <deny users="?" />
✓ Forms: It uses custom HTML forms to collect authentication information and lets you use </authorization>
your own logic to authenticate users. The users identification are stored in a cookie for use One can add more than one rule to the authorization section:
during the session. Syntax: <authencation mode= “forms”> <authorization>
✓ Passport: it uses Microsoft passport service to authenticate users. It maintain only <allow users="*" />
username and password. Syntax: <authencation mode= “password”> <deny users="?" />
</authorization>
b) What is XML? What are its basic characteristics?
e)Define Authentication and Authorization. Give types of Authentication. (5)

You might also like