0% found this document useful (0 votes)
5 views26 pages

AWD Unit 5

The document explains key concepts in XML and ASP.NET, including the XmlTextReader and XmlTextWriter classes for reading and writing XML data, respectively. It also covers authentication types, impersonation in ASP.NET, and the ASP.NET AJAX Control Toolkit, which provides various controls for enhanced web functionality. Additionally, it discusses XML's characteristics and the use of authorization rules in web.config for access control.

Uploaded by

jy193857.yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views26 pages

AWD Unit 5

The document explains key concepts in XML and ASP.NET, including the XmlTextReader and XmlTextWriter classes for reading and writing XML data, respectively. It also covers authentication types, impersonation in ASP.NET, and the ASP.NET AJAX Control Toolkit, which provides various controls for enhanced web functionality. Additionally, it discusses XML's characteristics and the use of authorization rules in web.config for access control.

Uploaded by

jy193857.yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Nov18

1)Explain XmlTextReader and XmlTextWriter with an example.


Ans: XmlTextReader is a class in the .NET Framework that used read XML data
quickly and efficiently.
it provides access to XML data in one direction (only forward) and is read-only.
The "current node" refers to the part of the XML that the reader is focused on.
The reader moves forward using any of the read methods, and the properties
show the value of the current node.
XmlTextReader provides the following functionality:
 Purpose:  o read XML data in a forward-only, read-only manner.

 Key Features:
Provides forward-only access to XML data.
Enforces the rules of well-formed XML but does not perform data validation.
Can read nodes such as elements, attributes, and text content sequentially.
Does not validate data against a DTD or schema but checks DocumentType
nodes for well-formedness.
Nodes of type XmlNodeType.EntityReference return an empty Value property.
Does not expand default attributes.
Syntax to Declare an XmlTextWriter Object:
XmlTextReader reader = new XmlTextReader (“XML1.xml”);
Example::
using System;
using System.Xml;

class Program
{
static void Main()
{
// Create an XmlTextReader to read the XML file
using (XmlTextReader reader = new XmlTextReader("details.xml"))
{
// Read through the XML file
while (reader.Read())
{
// Check the node type and process accordingly
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "FirstName")
{
Console.WriteLine("First Name: " +
reader.ReadElementContentAsString());
}
else if (reader.Name == "LastName")
{
Console.WriteLine("Last Name: " +
reader.ReadElementContentAsString());
}
else if (reader.Name == "College")
{
Console.WriteLine("College: " +
reader.ReadElementContentAsString());
}
}
}
}
}
}

1. Output of the Reader:


2. First Name: John
3. Last Name: Doe
4. College: ABC University

Xmltextwriter
Purpose: To create or modify XML documents.
Key Features:
>Provides methods to construct XML documents programmatically.
>Requires calling methods in the correct sequence to form a valid document.
>Starts with WriteStartDocument() and ends with WriteEndDocument().
>Allows nesting of elements using methods like WriteStartElement() and
WriteEndElement().
>Enables adding attributes to elements with WriteAttributeString().
>Supports indentation and formatting for better readability.

Example: using System;


using System.Xml;

class Program
{
static void Main()
{
// Create an XmlTextWriter instance to write XML data to a file
using (XmlTextWriter writer = new XmlTextWriter("details.xml")
{
// Set formatting to indented for better readability
writer.Formatting = Formatting.Indented;

// Start the document


writer.WriteStartDocument();

// Start the root element


writer.WriteStartElement("Details");

// Add some child elements with values


writer.WriteElementString("FirstName", "John");
writer.WriteElementString("LastName", "Doe");
writer.WriteElementString("College", "ABC University");

// End the root element


writer.WriteEndElement();

// End the document


writer.WriteEndDocument();
}

Console.WriteLine("XML file created successfully.");


}
}
Output:
XML file created successfully.

Explanation:
5. Writing XML:
o We use XmlTextWriter to write an XML document to a file named
details.xml.
o WriteStartElement starts a new element (like <Details>).
o WriteElementString adds child elements (like
<FirstName>John</FirstName>).
o Finally, WriteEndElement closes the elements, and
WriteEndDocument ends the XML document.
6. Reading XML:
o XmlTextReader reads the XML file details.xml.
o reader.Read() moves the reader to the next node.
o We check if the node is an element and then read the content of
elements like <FirstName>, <LastName>, and <College> using
ReadElementContentAsString().
7. Output of the Reader:
2)What is Xelement? Explain with an example.
Ans:
The `XElement` class in `System.Xml.Linq` represents an XML element.
`XElement` loads and parses XML. It allows us to remove a lot of old code and
reduces the chance of bugs and typing mistakes. The `XAttribute` class
represents an attribute of an element. The `XElement.Save` method saves the
content of an `XElement` to an XML file.
Example:
using System;
using System.Xml.Linq;

class Program
{
static void Main()
{
// XDocument का उपयोग करके XML दस्तावेज़ बनाना
XDocument doc = new XDocument(
new XElement("SuperProProductList",
new XElement("product",
new XAttribute("id", 1),
new XElement("name", "Super Pro 2000"),
new XElement("category", "Electronics"),
new XElement("price", 199.99)
),
new XElement("product",
new XAttribute("id", 2),
new XElement("name", "Super Pro 3000"),
new XElement("category", "Electronics"),
new XElement("price", 299.99)
)
)
);

// दस्तावेज़ को XML फ़ाइल में सेव करना


doc.Save("SuperProProductList.xml");

Console.WriteLine("XML document 'SuperProProductList.xml' saved");


}
}
} Q3 What do you mean by authentication? Explain its types.
Ans: Authentication is a process in which the identity of a user is verified to
allow access to an application. Typically, a user needs to provide a username
and password to be authenticated. Once the user is authenticated, they still
need permission to use the specific application. This permission process is
called **Authorization**, which is the step where the user is granted access to
use the application.
There are 3 types of authentication as follows:
Windows-based
Forms-based
Windows-liveid
1) **Windows-based authentication:**

- When a user tries to access a restricted page, it causes the browser to display
a login dialog box.
- It is supported by most browsers.
- It is configured through the IIS (Internet Information Services) management
console.
- It uses Windows user accounts and directory permissions to grant access to
restricted pages.

Advantages :
It keeps your password safe and uses encryption.
Users log in with their existing Windows account, so they don’t need to
remember multiple passwords.
All user accounts are managed in one place.
After logging in, user can use other apps without signing in again.
From developer's point of view, easy to implement.
Disadvantages:
It only works on Windows devices, so non-Windows users can’t use it easily.
If the server goes down, users can’t log in.
it’s hard to use with apps in the cloud.
If the server is hacked, all accounts are at risk.

2) **Forms-based authentication:**

- The developer creates a login form to collect the username and password.
- The username and password entered by the user are encrypted if the login
page uses a secure connection.
- It does not depend on Windows user accounts.
3) Windows Live ID authentication: ▪ It is centralized authentication service
offered by Microsoft. ▪ The advantage is that the user only has one maintain
one username and password.
file:///C:/Users/komal/Downloads/ITCS-AWP-converted.pdf 100

4) What do you mean by Impersonation in ASP.NET? Explain.


ASP.NET impersonation used to control the execution of the code in
authenticated and authorized client. It is not a default process in the ASP.NET
application. It is used for executing the local thread in an application.ASP.NET
impersonation is used to control the execution of the code in authenticated
and authorized client. It is not a default process in the ASP.NET application. It is
used for executing the local thread in an application. If the code changes the
thread, the new thread executes the process identity by default.
The impersonation can be enabled in two ways as mentioned below :
1 **Impersonation Enabled:**
When impersonation is enabled, ASP.NET uses the token provided by IIS. This
token can belong to an authenticated user or an internet user account.
**Syntax:** <identity impersonate="true" />
2. Impersonation enabled for a specific identity: ASP.NET impersonates the
identity specified in the Web.config file using a token.
SYNTAX: <identity
impersonate="true"
userName="domain\user"
password="password" />
3. **Impersonation Disabled:**
This is the default setting for ASP.NET applications.
When impersonation is disabled, the application runs using the identity of the
worker process, which is the ASP.NET account.
Syntax: <identity impersonate="false" />
5) ) Explain ASP.NET AJAX control toolkit.
Ans: ASP.NET AJAX Control Toolkit
The ASP.NET AJAX Control Toolkit is a joint project by Microsoft and the
ASP.NET community. It provides dozens of controls that create advanced
effects using ASP.NET AJAX libraries. This toolkit is completely free and
includes the full source code. It's especially useful for developers who want to
create custom controls using ASP.NET AJAX features.
How to Install ASP.NET AJAX Control Toolkit:
1. Download the toolkit from http://ajaxcontroltoolkit.codeplex.com.
2. Go to the Download tab and find the toolkit for the latest .NET version.
3. Once downloaded, extract the ZIP file to a permanent location on your
hard drive.
4. After installation, the toolkit components will appear in the Choose
Toolbox Items dialog under AjaxControlToolkit.dll.
Available Controls in the Toolkit:
 AutoComplete: Provides suggestions in a text box.
 Color Picker: Allows users to select colors.
 Calendar: For selecting dates.
 Modal Popup Extender: Creates modal popups.
 Slideshow Extender: For creating slideshows.
Important Facts About the Toolkit:
 It includes around 50 controls.
 For more information and tutorials, visit
www.asp.net/ajaxlibrary/act_tutorials.ashx.
 The toolkit is currently maintained by the DevExpress team.
 The latest version is v16.1.0.0, which includes new controls and bug fixes.

Nov 19
2) What is XML? What are its basic characteristics?
Ans: Defination of xml
XML stands for Extensible Markup Language. It is a commonly used format for
exchanging data because it is easy to read for both humans and machines.
If you have ever written a website in HTML, XML will feel familiar to you
because it is a stricter version of HTML.
XML uses tags, attributes, and values to structure data.
basic characteristics of xml
1)An XML element is made up of a **start tag** (like `<Name>`) and an **end
tag** (like `</Name>`). The content is placed between the start and end tags.
If we include a start tag, we must also include a matching end tag.
Another option is to create an **empty element**, where both the start and
end tags are combined with a **forward slash** at the end, and there is no
content (like `<Name />`).
This is similar to the syntax used in ASP.NET controls.
2) Whitespace between elements is ignored. That means we can freely use
tabs and hard returns to properly align(arrange) our information.
3)  Hierarchical Structure:
XML organizes data in a tree structure, with elements inside other elements,
making it easy to represent complex data.
4) Supports All Languages:
XML can store data in any language because it supports Unicode.
5) Strict Rules:
XML follows strict rules—every tag must be closed properly, and tags must be
arranged correctly
6) Used for Data Sharing:
XML is commonly used to share data between different systems or store data
in a structured way.
7) Platform-Independent:
XML can be used on any system or device, making it universal.
8) Human and Machine Readable:
XML is written in plain text, which makes it easy for both people and
computers to read and process.

3)xml ) What is the use of XMLTextWriter class? Explain various methods of


this class.
Methods of XMLTextWriter class:
1. WriteStartDocument()
 This method is used to write the XML declaration (<?xml version="1.0"?
>) at the beginning of the document.
 Syntax: WriteStartDocument()
2. WriteEndDocument()
 This method is used to close the XML document. It writes the closing
part of the document.
 Syntax: WriteEndDocument()
3. WriteStartElement(string localName)
 This method writes the start tag of an XML element.
 Syntax: WriteStartElement("ElementName")
 Example: <ElementName>
4. WriteEndElement()
 This method writes the end tag of the current element.
 Syntax: WriteEndElement()
 Example: </ElementName>
5. WriteElementString(string localName, string value)
 This method writes an element with the specified name and a string
value.
 Syntax: WriteElementString("ElementName", "ElementValue")
 Example: <ElementName>ElementValue</ElementName>
6. WriteAttributeString(string localName, string value)
 This method writes an attribute for the current element.
 Syntax: WriteAttributeString("AttributeName", "AttributeValue")
 Example: <ElementName AttributeName="AttributeValue">
7. WriteComment(string text)
 This method writes a comment in the XML.
 Syntax: WriteComment("This is a comment")
 Example: <!-- This is a comment -->
q. What is authorization? Explain adding authorization rules in web.config
file.
: Authentication is a process in which the identity of a user is verified to allow
access to an application. Typically, a user needs to provide a username and
password to be authenticated. Once the user is authenticated, they still need
permission to use the specific application. This permission process is called
**Authorization**, which is the step where the user is granted access to use
the application.
o control who can and cannot access our website, we need to add access-
control rules in the <authorization> section of the web.config file.
Example:
<configuration>
...
<system.web>
...
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" />
</authentication>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</configuration>
Here, * (the wildcard) means all users are allowed, including anonymous
users. This means anyone, even users who haven't logged in, can use the
application.
For More Restrictive Rules:
If you want to change this and allow only logged-in users, you can add this rule:
xml
<authorization>
<deny users="?" />
</authorization>
Here, ? (the wildcard) means that this rule will block all anonymous users. By
adding this rule to the web.config, you specify that unauthenticated users will
not be allowed to access the website.
This way, you can control user access to your application.

5) Explain the working of update progress control in detail.


 Main Purpose of UpdateProgress Control:
 It shows a message to the user when a time-consuming update is in
progress.
 How It Works:
 When you add an UpdateProgress control to a page, you can specify
content (like a loading message or animation) to display as soon as an
asynchronous request starts and hide it once the request is completed.
 Role of UpdatePanel in the Background:
 The UpdatePanel works asynchronously in the background. During this
time, the user may not realize that some process is happening.
 The Problem:
 If an asynchronous request takes time, the user might feel the page is
stuck or not working.
 This may lead to users clicking the same button multiple times,
increasing unnecessary load on the application and slowing it further.
 The Solution:
 The UpdateProgress control solves this problem.
 It displays a "wait message" or loading animation, informing the user
that the request is still being processed and will finish soon.
Example:
<form id="form1" runat="server"> <div
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager> <br /> <br />
<asp:UpdatePanel ID = "UpdatePanel1" runat = "server">
<ContentTemplate>
<asp:Label ID = "Label1" runat = "server" Font-Bold = "True" >
</asp:Label> <br /><br />
<asp:Button ID = "Button1" runat = "server" Text = "Click Here to Start"
onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel><br />
<asp:UpdateProgress runat = "server">
<ProgressTemplate>
<b>Loading please wait …</b>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</form>

6) Explain about implementation of timed refreshes of update panel using


timer.
Ans:
Apr 2019
2) Explain the reading process from an XML Document with example.
Ans:
5) Explain AJAX with its advantages and Disadvantages.
Ans:
Ajax can be defined as a set of tools used to create websites and web
applications. To understand Ajax, it’s best to see its role in web development.
The main purpose of Ajax is to update content asynchronously, meaning that
only the required parts of a webpage are updated without reloading the entire
page.
XML is a markup language, which means it is a coded language used to
annotate parts of a web document. This helps web browsers understand and
display the content properly for users.
Ajax combines various programming tools, such as JavaScript, HTML, DHTML,
XML (Extensible Markup Language), CSS (Cascading Style Sheets), DOM
(Document Object Model), and Microsoft Object.

History of Ajax
Ajax was initially developed in 1999 by Microsoft Outlook Web Applications,
but its widespread use started 6 years later. The term Ajax was coined by Jesse
James Garrett in February 2005.
Before being called Ajax, it was known as XML HttpRequest Scripting Object
and operated using the MSXML Library.
Definiation of ajax
The full form of Ajax is Asynchronous JavaScript and XML.
It refers to a process where a user interacts with a web server using JavaScript
to send a request and display the response on the webpage without leaving or
reloading the current page.

Advantages :
. Reduces the server traffic and increases the speed.
2. Ajax is responsive and time taken is also less.
3. Form validation.
4. Bandwidth usage can be reduced.
5. Only update part of the page, no need to reload everything.
7. Sends only needed data, reducing server load.
8. Pages feel quick and smooth.
9. Runs on most devices and browsers.
10. esasy to use Works with HTML, CSS, and JavaScript.

Disaavantage of ajax:
1. If JavaScript is turned off in the browser, Ajax won’t work.
2. If the internet is slow, Ajax requests may fail or take longer.
3. Finding and fixing problems in Ajax code can be tricky.
4. Older browsers or less powerful devices might not support Ajax
fully, leading to functionality problems.
5. Ajax doesn't update the browser's history, so users can't use the
back or forward buttons easily.
6. Open-source.
3. Define Authentication and Authorization. Give types of Authentication.
ANS:  Authentication and Authorization are two related security concepts.
 Authentication is the process of verifying who the user is.
 Authorization is the process of checking if the authenticated user has access
to the requested resources.

There are two forms of authorization available in ASP.NET:


o FileAuthorization: i
t is performed by the FileAuthorization Module. It uses the access control list
of the .aspx file to resolve(decide) whether a user should have access to the
file. ACL permissions are confirmed for the users windows identity.
**URL Authorization:** - Authorization rules can be defined in the
**Web.config** file using the <authorization> element. - This allows setting
access rules for specific directories or files.

6) Give brief information on Accordion control with appropriate properties.


Ans: definition: accordion control
The Accordion control in ASP.NET is a part of the AJAX Control Toolkit. It is a
web server control used to display collapsible panels in a stacked manner,
where one panel can be expanded at a time while others are collapsed. This
provides an interactive and space-efficient way to display content.

Important Properties of Accordion Control


1. HeaderCssClass:
o Specifies the CSS class for the header of each panel.
o Example: "accordion-header"
2. ContentCssClass:
o Specifies the CSS class for the content area of each panel.
o Example: "accordion-content"
3. SelectedIndex:
o Determines the index of the panel that is initially expanded.
o Example: SelectedIndex="0" (expands the first panel).
4. FadeTransitions:
o Enables smooth fading transitions when switching between
panels.
o Example: FadeTransitions="true"
5. TransitionDuration:
o Specifies the duration (in milliseconds) of the transition animation.
o Example: TransitionDuration="500"
6. RequireOpenedPane:
o Ensures that at least one panel is always open.
o Example: RequireOpenedPane="true"
7. AutoSize:
o Adjusts the height of the Accordion based on the content.
o Values:
 "None": Height remains static.
 "Fill": Accordion fills the parent container.
 "Limit": Accordion adjusts up to a maximum height.
8. SuppressHeaderPostbacks:
o Prevents postbacks when the header is clicked.
o Example: SuppressHeaderPostbacks="true"

Example Usage:
<ajaxToolkit:Accordion ID="Accordion1" runat="server" SelectedIndex="0"
HeaderCssClass="accordion-header" ContentCssClass="accordion-content"
FadeTransitions="true" TransitionDuration="500" AutoSize="None">

<Panes>
<ajaxToolkit:AccordionPane>
<Header>Section 1</Header>
<Content>
<p>This is the content for section 1.</p>
</Content>
</ajaxToolkit:AccordionPane>
<ajaxToolkit:AccordionPane>
<Header>Section 2</Header>
<Content>
<p>This is the content for section 2.</p>
</Content>
</ajaxToolkit:AccordionPane>
</Panes>
</ajaxToolkit:Accordion>

Nov 22
using System;
using System.Xml.Linq;

class Program
{
static void Main()
{
// Create the XML structure using XElement
XElement employee = new XElement("employee",
new XElement("empId", 3),
new XElement("empName", "TS"), // Changed from cmpName to
empName
new XElement("empDept", "IT"), // Changed from empDep to empDept
new XElement("empDesignation", "MANAGER") // Changed from
cmpDesignation to empDesignation
);

// Save the XML to a file


employee.Save("employee.xml");

// Print the XML to the console


Console.WriteLine(employee);
}
}

What is XML? List and explain the various XML classes.


Xml
Xmltextwriter
Xmltextreader
Xmldocument

What do you mean by “authentication”? Describe its various types of


authentications.

You might also like