UNIT-4 NOTES(1)
UNIT-4 NOTES(1)
(CS)
Distributed Technologies
Unit IV
Advanced Features of ASP.NET
ASP.Net is an exciting server side technology used for developing web based applications
It uses the namespaces, classes and methods provided by the .NET Framework
o MasterPage
o Data Control
o Navigation Control
Master Page:
o is use to define common structure and interface elements for any website
Data Control
o Data access can possible by using the new data-bound and data source controls
o New data source controls to represent different data backend, such as SQL, business
objects, and XML
o New data-bound controls for rendering common UI for data, such as grids, details, and
formview
o Theme to control the appearance of both the HTML elements and ASP.NET controls
that appear in a page
o A Theme folder can contain a variety of different types of files, including images and
text files
o Also can organize the contents of a Theme folder by adding multiple subfolders to a
Theme folder
▪ A Skin enable to modify any of the proprieties of an ASP.net control that have
an effect on its appearance
Navigation control:
▪ Treeview
▪ Menus
▪ SiteMapPath
▪ Login security
▪ Wizard navigation
▪ Image generation
▪ Menus
▪ Tree views
▪ Portals
▪ And more
Security in ASP.NET
The authentication and authorization of users and resistance against the malicious attacks are
important tasks in web applications
ASP.NET 2.0 introduced a new membership and role management service that provides both
authentication and authorization services and management of users who access our application
without building any tables or writing any code
➢ Security Model
o Membership Provider
o Role Provider
➢ Membership Provider:
The extensible Membership provider framework can register and authenticate new users
o SqlMembership Provider:
▪ can also create custom Membership provider using any OLEDB DataSource or
XML DataSource
o AccessMembership Provider:
➢ Role Provider:
Role Provider are used to manage user roles like creating new roles for users
o ApplicationName:
o ConnectionStringName:
o Description:
o EnablePasswordReset:
▪ When true, users can reset their password to a randomly generated password
o EnablePasswordRetrieval:
▪ When true, user passwords can be retrieved from the Membership provider
o PasswordFormat:
• Clear
• Encrypted
• Hashed
▪ When passwords are hashed, the original passwords cannot be retrieved from the
Membership provider
o RequiresQuestionAndAnswer:
▪ When true, the user must answer a password retrieval question before the user
password can be reset or retrieved
o RequiresUniqueEmail:
▪ When true, a unique e-mail address must be associated with each user
3. Explain in detail the Different Login and Password Server Controls:
o Login
o LoginStatus
o LoginName
o ChangePassword
o PasswordRecovery
o LoginView
o CreateUserWizard
The Login server control display standard login interface for user authentication
The login control can be used as a standalone control on a main and home page or can use it
on a dedicated login page
Password
▪ FailureText: used to control the content and appearance of the text that is
displayed when a login attempt fails
This control enables user to click a link to Login or Logout of web application
Source code:
<form id="form1" runat="server">
<asp:LoginStatus ID="LoginStatus1" runat="server" />
</form>
Source code:
<form id="form1" runat="server">
<asp:LoginName ID="LoginName1" runat="server" />
</form>
This control displays textboxes for entering the original password and entering a new
password
New Password
The Confirm New Password must match the New Password entry
Source code:
<form id="form1" runat="server">
<asp:ChangePassword ID="ChangePassword1" runat="server">
</asp:ChangePassword>
</form>
Submit
Source code:
<form id="form1" runat="server">
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
</asp:PasswordRecovery>
</form>
Can be used to display different content depending on the role of the current user
Source code:
<form id="form1" runat="server">
<asp:LoginView ID="LoginView1" runat="server">
</asp:LoginView>
</form>
Used to allow users to create a new user entry in the membership system
Password
Confirm Password
E-mail
Security Question
Security Answer
Create User
Source code:
Source Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Login ID="Login1" runat="server" Height="239px" Width="595px">
</asp:Login>
</form>
</body>
</html>
View Code:
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Dim con As New SqlConnection
Dim ad As New SqlDataAdapter
Dim ds As New DataSet
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
con = New SqlConnection
con.ConnectionString = "Datasource"
con.Open()
ad = New SqlDataAdapter("select * from test Name='" & Login1.UserName & "' and No=" &
Login1.Password, con)
ds = New DataSet
ad.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
Response.Write("You are authenticate user")
Else
Response.Write("Incorrect user")
End If
End Sub
End Class
State Management in ASP.NET
Statement is the process by which we maintain state and page information over multiple
requests for the same or different pages
This stores information on the client’s computer by embedding the information into a web
page, a Uniform Resource Locator (URL) or a cookie
This techniques available to store the state information at the client end are listed below:
a. View State
b. Control State
c. Hidden Fields
d. Cookies
e. Query Strings
a. View State
▪ This property provides dictionary object for retaining values between multiple
request for the same page
▪ When the page is processed, the current state of the page and controls is hashed
into a string and saved in the page as a hidden field
▪ It is used by the Asp.net page framework to automatically save the values of the
page and of each control just prior to rendering to the page
▪ We can store values in view state as well. The following example shows how
to store a value in the view state
ViewState(“color”)=”red”
b. Control State
▪ To store control-state data in order for a control to work properly the control
state is used
c. Hidden Fields
▪ Hidden fields store data in an HTML form without displaying it in the user’s
browser
d. Cookies
▪ A cookie is a small amount of data that is store a value in the user’s browser
that the browser sends with every page request to the same server
▪ The most common use of cookies is to identify a single user as he or she visits
multiple web pages
e. Query Strings
http://www.contoso.com/listwidgets.aspx?category=basic&price=100
a. Application State
▪ Is used to store and retrieve information that can be shared among all user of an
application
b. Session State
▪ Used to store and retrieve information about particular sessions
▪ Both Application state and Session state information is lost when the application restart
c. Profile Properties
▪ Profile.postalcode=textbox1.text
ASP.NET provides a mobile component which allows we to build applications for mobile
devices to access web pages
Mobile ASP.Net pages are based on the MobilePage class which exists in
System.Web.UI.MobileControls namespace
Uses on a mobile ASP.NET page come from their own namespace, we need to include that
namespace on each of our mobile ASP.Net pages
Example :
2. On the File Menu, choose New, and then choose Web Site. The New Web Site dialog box
appears
6. Language Visual C#
7. Click OK button
3. Right-click the application in Solution Explorer and choose Add New Item
5. Name Calculator.aspx
Mobile Controls
1. Label Control
2. Link Control
Provides, to allow the visitors to navigate to another page or another form within the
current page
<mobile:Form id=”Form1” runat=”server” >
<mobile:Label id=”Label1” runat=”server” Text=”Link Test Page”/>
<mobile:Link id=”Link1” runat=”server” Text=”click here!”
NavigateUrl=”http://www.google.com” />
<mobile:Link id=”Link2” runat=”server” Text=”or here!”
NavigateUrl=”http://www.gmail.com” Alignment=”Right”/>
</mobile:Form>
3. Call Control
Use the Call Control to make it easier for the visitor to call the contact
That supports dialing phone numbers. If the visitor were to click the call control, they
would e asked to confirm that they wanted to make the call
4. Image Control