Assignment 2019 For Others
Assignment 2019 For Others
UNIT – 1
Q.1) What are .NET languages? Explain various features of C# languages.
The Microsoft .Net Framework provides the necessary foundation for developing windows as
well as web applications. The unique feature of .NET is the multi-language support that it
provides. To help create languages for the .NET Framework, Microsoft created the Common
Language Infrastructure specification (CLI). The CLI describes the features that each language
must provide in order to use the .NET Framework and common language runtime. The .NET
platform supports many languages and the list is growing day by day. The C# compiler is
considered to be the most efficient compiler in the .NET family.
Features of C#:
Modern: C# is a modern programming language that incorporates contemporary
programming paradigms and features. It's continuously updated by Microsoft to keep up with
evolving industry standards.
Type-Safe: As mentioned earlier, C# is a strongly typed language. This means that the type of
a variable is checked at compile time, which helps catch type-related errors early in the
development process.
Interoperable: C# is designed to work seamlessly with other languages within the .NET
ecosystem. This allows developers to use components written in different languages within the
same application.
Object-Oriented: C# is a fully object-oriented language. It supports classes, objects,
inheritance, encapsulation, and polymorphism, which are fundamental concepts in object-
oriented programming (OOP).
Easy to Learn: C# was designed with ease of learning and readability in mind. Its syntax is
clean and intuitive, making it accessible to beginners while still being powerful enough for
experienced developers.
Q.2) What is property? Explain read-write property with proper syntax and example.
In object-oriented programming, a property is a feature of a class that provides access to an
underlying data member or field. It allows you to get (read) or set (write) the value of that data
member in a controlled manner. Properties are used to expose the state of an object while
encapsulating the implementation details.
A read-write property is a property that allows both reading and writing of its underlying value.
Here's the syntax for creating a read-write property in C#:
public datatype PropertyName
{
get
{
// return the value of the property
}
set
{
// set the value of the property
}
}
Here's an example to demonstrate a read-write property in a C# class:
public class Person
{
private string name;
In this example, we have a `Person` class with a private field `name`. We've defined a read-
write property called `Name` which allows us to get and set the value of name.
Here's how you would use the Person class:
Person person = new Person();
person.Name = "John"; // Set the value using the property
string personName = person.Name; // Get the value using the property
In the above code, we create an instance of the `Person` class and use the `Name` property to
set and get the value of the `name` field.
Using properties allows you to control access to your class's data and add validation or logic
if needed. It also helps maintain clean and readable code.
class Program
{
static void Main()
{
Dog dog = new Dog();
Q.6) List various reference types in c#. Also explain boxing operation with example.
List of reference type
interface type
delegate type
array type
class type
strings
The reference type hold references to the values stored somewhere in memory. You can
imagine a reference type similar to a pointer that is implicitly dereferenced when you access
them.
Boxing is an implicit conversion of a value type on the stack to an object on the
heap. Boxing a value allocates an object instance and copies the value into the new object.
Boxing enables value type variables to act like objects. Consider the following declaration of
a value-type variable:
int i = 123;
The following statement implicitly applies the boxing operation on the variable i:
object o = i;
The result of this statement is creating an object o, on the stack, that references a value of the
type int, on the heap. This value is a copy of the value-type value assigned to the variable i.
On the stack On the heap
50
Int i = 123; (i boxed)
Int
50
UNIT – 2
Q.1) What are .aspx files? Explain code behind class file in detail.
In ASP.NET web applications, the UI code is present in the .aspx file. This file mainly contains
HTML and control markups. The program logic is written in a separate file called code behind
file. The code behind file has the extension . aspx.cs. There is a code behind file associated
with each page of a website. As the program logic is separated from user interface design code,
this model is easy to understand. The code for the page is compiled into a separate class from
which the .aspx file derives. Only server controls can interact with the code behind the page;
not the HTML controls.
Q.2) Explain each of the following in brief:
i. Web forms
ii. Post back
iii. Page rendering
iv. Page Load event
v. Page PreRender event
The Web Forms are web pages built on the ASP.NET Technology. Web Forms are pages that
users request using their browser. These pages can be written using a combination of HTML,
client-script, server controls, and server code.
The process of submitting an ASP.NET page to the server for processing is termed as post
back. The post back originates from the client side browser. The Page object has an
IsPostBack property, which is tells whether the request is a fresh request or a post back.
The user sends a request for a page to the server through the browser. The server inspects the
request and compiles it. The response object is created and renders the HTTP response back
to the browser. The browser receives the response, and parses the HTML in the response.
Page_Load
• Load is raised for page first and recursively for all child controls.
• In the event handler associated with this event you can write code that needs to be
executed for each postback of the web page.
protected void Page_Load(object sender, EventArgs e){}
PreRender
• Raised after the Page object has created all controls that are required in order to render the
page.
• It occurs for each control on the page.
• It is raised for the Page first and recursively for all child controls.
• This event can be used to make final changes to the contents of the page or its controls
before rendering the page.
• This event can be handled by Page_PreRender handler.
protected void Page_PreRender(object sender, EventArgs e){}
Q.3) List any four category of server controls in asp.net? Explain common properties of
web server controls.
Category of server controls
Standard controls
Data controls
Validation controls
Navigation controls
Property Description
AccessKey Enables you to set a key with which a control can be accessed at the
client by pressing the associated letter.
BackColor, Enables you to change background color and text color of a control.
ForeColor
BorderColor This property is used to change the border color of a control.
BorderStyle Using this property border Style can be set to none, dotted, dashed, solid
double, groove etc.
BorderWidth Enables you to change border width of a control.
CssClass Enables you to set the style sheet class for this control.
Enabled Determines whether the control is enabled or not. If the control is
disabled user cannot interact with it.
Font Enables you to change the Font settings.
Height Enables you to set the height of the control.
Width Enables you to set the width of the control.
ToolTip This property enables you to set a tooltip for the control in the browser
and is rendered as a title attribute in the HTML, is shown when the
user hovers the mouse over the control.
Visible Determines whether the control is visible or not.
Q.4) Explain the basic functionality of each of the following webserver controls.
i. CheckBox
ii. TextBox
iii. DropDownList
iv. Menu
i. CheckBox:
The CheckBox control is an input control that allows the user to toggle between two states:
checked and unchecked.
It is commonly used when you want to present the user with a binary choice, such as agreeing
to terms and conditions.
The state of a CheckBox can be determined on the server side when a form is submitted.
Example in ASP.NET:
<asp:CheckBox ID="checkBox1" runat="server" Text="Agree to Terms" />
ii. TextBox:
The TextBox control provides an input field for users to enter text or numeric data.
It is widely used for forms where users need to input information like names, emails,
passwords, etc.
The entered data can be accessed on the server side for further processing.
Example in ASP.NET:
<asp:TextBox ID="textBox1" runat="server" />
iii. DropDownList:
The DropDownList control provides a list of options, and the user can select one from the list.
It is used when you want to present a set of choices to the user, such as selecting a country,
state, or category.
The selected item can be accessed on the server side for processing.
Example in ASP.NET:
<asp:DropDownList ID="dropDownList1" runat="server">
<asp:ListItem Text="Option 1" Value="1" />
<asp:ListItem Text="Option 2" Value="2" />
<asp:ListItem Text="Option 3" Value="3" />
</asp:DropDownList>
iv. Menu:
The Menu control provides a hierarchical menu system for website navigation.
It is used to create navigation menus with submenus and allows users to easily navigate
between different sections of a website.
The menu items can be defined and configured in the markup or dynamically generated in
code.
Example in ASP.NET:
<asp:Menu ID="menu1" runat="server">
<Items>
<asp:MenuItem Text="Home" NavigateUrl="~/Home.aspx" />
<asp:MenuItem Text="Products">
<asp:MenuItem Text="Product 1" NavigateUrl="~/Products/Product1.aspx" />
<asp:MenuItem Text="Product 2" NavigateUrl="~/Products/Product2.aspx" />
</asp:MenuItem>
<asp:MenuItem Text="Contact" NavigateUrl="~/Contact.aspx" />
</Items>
</asp:Menu>
RegularExpressionValidator
• The RegularExpression Validator control is used to ensure that an input value matches a
specified pattern.
• These patterns are called regular expressions or regex.
• Patterns consists of literal characters and special characters.
Literal characters are normal characters with no special meaning whereas special characters
have special meaning in the pattern.
Q.6) What are rich controls? Explain about Calendar and AdRotator controls in brief.
Rich controls are web controls that model complex user interface elements. A typical rich
control can be programmed as a single object but renders itself using a complex sequence of
html elements. Rich controls can also react to user actions and raise more-meaningful events
that your code can respond to on the web server. In other words, rich controls give you a way
to create advanced user interfaces in your web pages without writing lines of convoluted
html.
The Calendar control presents a miniature calendar that you can place in any web page. Like
most rich controls, the Calendar can be programmed as a single object, but it renders itself
with dozens of lines of HTML output.
<asp:Calendar id="MyCalendar" runat="server" />
The Calendar control presents a single-month view. The user can navigate from month to
month by using the navigational arrows, at which point the page is posted back and ASP.NET
automatically provides a new page with the correct month values.
The basic purpose of the AdRotator is to provide a graphic on a page that is chosen randomly
from a group of possible images. 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.
One use of the AdRotator is to show banner-style advertisements on a page, but you can use
it anytime you want to vary an image randomly.
UNIT – 3
Q.1) Explain exception handling mechanism with proper syntax and example.
An exception is an event that interrupts normal program execution. There are two aspects
involved in the processing of exceptions: raising (or throwing) the exception and handling
the exception. The steps involved in exception handling are:
Detect problem-causing exception (hit the exception).
Inform that an error has occurred (throw the exception).
Receive error information (catch the exception).
Take corrective actions (handle the exception).
In C#, the try and catch block used for handling exception has the following syntax:
Try with multiple catch Try block with catch and Try block with only
block finally block finally block
try{ statements; } try{ statements; } try
catch(ExceptionType obj) catch(ExceptionType obj) { statements; }
{ statements; } { statements; } finally {
catch(ExceptionType obj) Finally { statements; } statements; }
{ statements; }
A try block must have a catch block or a finally block. There can be multiple catch blocks
but a single finally block for a try block. The normal scope rules apply for the try block. For
instance any local variable defined in the try block will not be accessible outside the block.
Example :-
try{
int n=Convert.ToInt32(Console.ReadLine());
System.Console.WriteLine("n="+n);
}catch(FormatException e) { }
Q.6) What are the three different ways to use styles on web pages? Explain various
category of style setting in New Style dialog box.
Web pages can use styles in three different ways:
Inline style: An inline style is a style that’s placed directly inside an HTML tag. This
can get messy, but it’s a reasonable approach for one-time formatting. You can
remove the style and put it in a style sheet later.
Internal style sheet: An internal style sheet is a collection of styles that are placed in the
<head> section of your web page markup. You can then use the styles from this style sheet
to format the web controls on that page. By using an internal style sheet, you get a clear
separation between formatting (your styles) and content (the rest of your HTMLmarkup). You
can also reuse the same style for multiple elements.
External style sheet: An external style sheet is similar to an internal style sheet, except
it’s placed in a completely separate file. This is the most powerful approach because it
gives you a way to apply the same style rules to many pages.
Category Description
Font Allows you to do all font settings
Block Allows you to fine-tune additional text settings. Example:-text
alignment, test indentation, spacing between letters and words, etc.
Background Allows you to set a background color or image
Border Allows you to do border setting.
Box Allows you to define the margin and the padding
Position Allows you to set a fixed width and height for your element, and use
absolute positioning to place your element at a specific position on the
page.
Layout Allows you to control miscellaneous layout settings.
List If you’re configuring a list (a <ul> or <ol> element), you can set the
numbering or bullet style.
These settings aren’t commonly used in ASP.NET web pages because
you’re more likely to use ASP.NET list controls like the BulletedList.
Table Allows you to set details that only apply to table elements (such as and
). For example, you can control whether borders appear around an
empty cell.
UNIT – 4
Q.1) What is data binding? Explain repeated value data binding with example.
Data binding is the process how the user interface controls of a client application are
configured to retrieve from, or update data into, a data source. It provides a simple and
consistent way for applications to present and interact with data. If the user modifies the data
in a data-bound control, your program can update the corresponding record in the database.
Repeated-value data binding works with the ASP.NET list controls. To use repeatedvalue
binding, you link one of these controls to a data source (such as a field in a data table). Then
you call DataBind(), the control automatically creates a full list by using all the corresponding
values.
Following are the steps.
1. Create and fill some kind of data object such as arrays, ArrayList, Hashtable,DataTable
and DataSet
2. Link the object to the appropriate control.
3. Activate the binding using DataBind() method.
A Simple List-Binding Example
public List<string> GetCarsList()
{
List<string> cars = new List<string>();
cars.Add("Santro"); cars.Add("Marazzo"); cars.Add("i20"); cars.Add("Ertiga");
cars.Add("Brezza"); cars.Add("Tigor"); cars.Add("Creta");
return cars;
}
protected void Page_Load(object sender, EventArgs e)
{
lstItems.DataSource=GetCarsList();
this.DataBind();
}
Q.2) Write any three similarities between FormView and DetailsView. Explain about
item templates of FormView.
Like DetailsView, FormView also displays a single record from the data source at a time. Both
controls can be used to display, edit, insert and delete database records but one at a time. Both
have paging feature and hence support backward and forward traversal.
ItemTemplate is used to display the data from data the source in ReadOnly mode. The controls
included in an ItemTemplate are controls that only display data, such as a Label control. The
template can also contain command buttons to change the FormView control’s mode to insert
or edit, or to delete the current record. The ItemTemplate template can include Link Button
controls that change the mode of the FormView control based on the Command Name value.
A CommandName value of New puts the record into insert mode and loads the
InsertItemTemplate, which allows the user to enter values for a new record. You can add a
button with a CommandName value of Edit to the ItemTemplate template to put the FormView
control into edit mode. A button with a CommandName value of Delete can be added to the
ItemTemplate template to allow users to delete the current record from the data source.
Q.6) Describe asp.net provider model and direct data access method.
ADO.NET has a set of classes that are used to connect to a specific data source. Each set of
data interaction classes is called an ADO.NET data provider. ADO.NET data provider includes
SQL Server Data Provider, Oracle Data Provider, OLEDB Data Provider and ODBC Data
Provider. The classes used to connect to a specific data source includes Connection, Command,
DataReader and DataAdapter.
Connection is used to establish a connection to a specific data source.
Command is used to execute SQL statements against the data source.
DataReader is used to read data from data source.
DataAdapter populates a DataSet and resolves updates with the data source.
Each provider designates its own prefix for naming classes. Thus, the SQL Server provider
includes SqlConnection and SqlCommand classes, and the Oracle provider includes
OracleConnection and OracleCommand classes. Internally, these classes work quite
differently, because they need to connect to different databases by using different low-level
protocols. Externally, however, these classes look quite similar and provide an identical set of
basic methods because they implement the same common interfaces.
Using Direct Data Access
To query information with simple data access, follow these steps:
1. Create Connection, Command, and DataReader objects.
2. Use the DataReader to retrieve information from the database, and display it in a control on
a web form.
3. Close your connection.
4. Send the page to the user. At this point, the information your user sees and the information
in the database no longer have any connection, and all the ADO.NET objects have been
destroyed.
To add or update information, follow these steps:
1. Create new Connection and Command objects.
2. Execute the Command (with the appropriate SQL statement).
UNIT – 5
Q.1) Briefly explain different types of authentication in asp.net.
In ASP.NET, there are several types of authentication mechanisms that you can implement to
secure your web applications. Here are the different types of authentication in ASP.NET:
Windows Authentication:
Windows Authentication is a method where the user's credentials are verified against
the Windows user accounts on the server or a domain controller.
It is commonly used in corporate environments where users are already authenticated
through their Windows credentials.
This method is suitable for intranet applications.
Forms Authentication:
Forms Authentication allows you to create your own login page and authenticate users
against a custom user database, typically stored in a database or a custom data source.
It's a flexible authentication mechanism that allows you to implement custom login
logic.
This method is commonly used for public-facing websites and applications.
Passport Authentication:
Passport Authentication was a feature provided by Microsoft for authentication across
multiple websites or applications using a single set of credentials.
However, as of my knowledge cutoff date in January 2022, Passport Authentication has
been deprecated.
Cookie Authentication:
Cookie Authentication involves issuing a token (typically a secure cookie) to the client
upon successful authentication. This token is sent with each subsequent request to
identify the user.
It's commonly used in conjunction with Forms Authentication or other custom
authentication mechanisms.
This method is suitable for building stateful web applications.
Token-Based Authentication:
Token-Based Authentication involves generating a secure token (JWT - JSON Web
Token) upon successful authentication. This token is then sent with each request in the
headers to validate the user's identity.
It's widely used in modern web applications, especially those with Web APIs
(Application Programming Interfaces).
OAuth and OpenID Connect:
OAuth and OpenID Connect are industry-standard protocols used for delegating
authentication and authorization between applications.
OAuth is primarily focused on authorization, while OpenID Connect builds on top of
OAuth to provide authentication.
Client Certificate Authentication:
Client Certificate Authentication involves using SSL/TLS certificates to authenticate
clients. The server verifies the client's identity using their public key certificate.
This method is suitable for applications that require a high level of security.
Basic Authentication:
Basic Authentication involves sending the username and password with each HTTP request.
However, it's considered less secure because credentials are sent in plain text (unless used over
HTTPS).
Digest Authentication:
Digest Authentication is an improvement over Basic Authentication. It sends hashed
credentials rather than plain text. However, it's still less secure compared to other modern
methods like Forms or Token-Based Authentication.
Q.2) What is XML? What are its basic characteristics?
• XML elements are composed of a start tag and an end tag. Content is placed
between the start and end tags.
Eample:-
<ProductName> Camera </ProductName> //element composed of start tag
and an end tag
<ProductName /> //combined start tag and an end tag representing empty
element
• Whitespace between elements is ignored.
• You can use only valid characters in the content for an element. (You can’t
enter special characters, such as the angle brackets (< >) and the ampersand
(&), as content.)
use < for <, > for >, & for &
• XML elements are case sensitive.
• All elements must be nested in a root element.
• Every element must be fully enclosed.
• XML documents usually start with an XML declaration like <?xml
version="1.0"?>. This signals that the document contains XML and indicates
any special text encoding. However, many XML parsers work fine even if this
detail is omitted.
Q.3) What is the use of XMLTextWriter class? Explain various methods of this class.
The XmlTextWriter class allows you to write to XML files. The Constructor for creating an
instance of the
XmlTextWriter class is:
XmlTextWriter (Stream, Encoding)
If encoding is null it writes out the stream as UTF-8.
string file =Path.Combine(Request.PhysicalApplicationPath,"XMLFile.xml");
FileStream fs = new FileStream(file, FileMode.Create);
XmlTextWriter w = new XmlTextWriter(fs, null);
Q.4) What is authorization? Explain adding authorization rules in web.config file.
Authorization: Authorization is the process of determining whether a user has sufficient
permission to perform a given action. To control who can and can’t access your website,
you need to add access-control rules to the <authorization> section of your web.config
file.
<configuration>
...
<system.web>
...
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" />
</authentication>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</configuration>
The asterisk (*) is a wildcard character that explicitly permits all users to use the
application—even those who haven’t been authenticated. The question mark (?) is a
wildcard character that matches all anonymous users. By including following rule in
applications web.config file, you specify that anonymous users are not allowed.
<authorization>
<deny users="?" />
</authorization>
One can add more than one rule to the authorization section:
<authorization>
<allow users="*" />
<deny users="?" />
</authorization>