Upload
ganesh-jaya
View
267
Download
3
Tags:
Embed Size (px)
DESCRIPTION
Asp.Net Basic Notes For Freshers PPT
Citation preview
1
2
Index1. .Net Introduction
2. Asp.Net Introduction
3. Controls
4. State Management
5. Asp.Net Objects
6. Asp.Net Web Application
7. Assembly
8. Caching
9. Security
9. Debugging
10. Tracing
11. Web Services
12. AJAX
3
4
1. .Net Introduction
2. The Origins of .Net Technology
3. The .Net Framework
4. .Net Languages
5. Benefits Of The .Net Approach
Contents
5
.Net Introduction
Definition:
.Net is a software framework that includes everything required for developing software for web services
It integrates presentation technologies,component technologies and data technologies on a single platform.
Microsoft took many of the best ideas in the industry,added their own creativity and innovations and produced a coherent systems solution popularly known as Microsoft .NET
Microsoft .Net Platform Includes
1. .NET infrastructure and Tools
2. .Net user experience
3. .Net building block
4. .Net device Software
6
The Origins Of .Net TechnologyThe current technology of .Net has gone through three significant
phases of development :
1. OLE Technology
2. COM Technology
3. .NET Technology
OLE Technology:
To embed documents from one applications into another application.
To enable one application to manipulate objects located in another application
Ex:MS Word and MS Excel
COM Technology
Reduces the overall complexity of software
Enables distributed development across multiple organizations or departments
Enhances Software Maintainability
.NET Technology
Third-Generation Component Model
It Provides a new level of inter-operability compared to COM technology.
It Uses Intermediate language(MSIL)for compilation.
7
.Net Framework
The .Net framework is one of the tools provided by the .NET infrastructures and tools component of the .NET platform.
.Net platform provides a new environment for creating and running robust,scalable and distributed applications over the web.
Definitions
The .NET framework provides an environment for building,deploying and running web services and other applications.
The Main components are
•Common Language Runtime(CLR)
•Framework Base Classes
•User and program interfaces.
Click Here to Enlarge
8
Common Language Runtime(CLR)
•The common Language Runtime,popularly known as CLR is the heart and soul of the .NET framework.
•It is runtime environment in which programs written c# and other .NET languages are executed.
•It also supports Cross-Language Interoperability
The CLR is the core of the.NET framework and is responsible for loading and running C# programs
The CLR provides a number of services that include
Loading and execution of programs
Memory isolation for applications
Verification of type safety
Compilation of IL into native executable code
Providing metadata
Memory Management
Enforcement of security
Interoperability with other systems
Managing exceptions and errors
Support for tasks such as debugging and profiling
Click Here To Enlarge
9
CLR Components
Common Type System(CTS)
The .Net frame work provides multiple language support using the feature known as Common Type System that is built into the CLR.The CTS supports a variety of types and operations found in most programming languages and therefore calling one language from another language does not require type conversions.
Common Language Specification
The common Language specification defines a set of rules that enables interoperability on the .NET Platform.These rules serve as a guide to third-party compiler designers and library builders.The CLS is a subset of CTS and therefore the languages supporting the CLS can use other’s class libraries as if their own.Application Program Interface(APIs) that are designed following the rules of CLS can easily be used by all the .NET Languages.
Microsoft Intermediate Language(MSIL)
MSIL,or simply IL,is an instruction set into which all the .NET programs are compiled.It is akin to assembly language and contains instructions for loading,storing,initializing and calling methods.When we compile a C# program or any program written in CLS-Compliant language,the source code is compiled into MSIL
Managed Code
As we know,the CLR is responsible for managing the execution of code compiled for the .NET platform.The code that satisfies the CLR at runtime in order to execute is referred to as managed Code.Compilers that are compatible to the .Net platform generate managed code.
10
Framework Base Classes
.Net supplies a library of base classes that we can use to implement applications quickly.We can use them by simply instantiating them and invoking their methods or by inheriting them through derived classes,thus extending their functionality.
Much of the functionality in the base framework classes resides in the vast namespace called System
The system namespaces included
Input/Output Operations
String Handling
Managing arrays,lists,maps,etc
Accessing files and file systems
Accessing the registry
Security
Windowing
Window messages
Database Management
Evaluation of mathematical functions
Drawing
Managing errors and exceptions
Connecting to the internet and etc..
Click Here To Enlarge
11
USER AND PROGRAM INTERFACES
The .NET framework provides the following tools for managing user-and application interfaces:
•Windows Forms
•Web Forms
•Console Applications
•Web Services
These tools enable users to develop user-friendly desktop-based as well as web-based applications using a wide variety of languages on .NET platform
12
.NET Languages
The .NET framework is language neutral.Currently,we can use a number of languages for developing .NET applications.They include:
Native to .NET
• C#(Specially created for .NET)
• C++
• Visual Basic
• Jscript
Third Party Languages
•COBOL
•Eiffel
•Perl
•Python
•SmallTalk
•Mercury
•Scheme
All .NET languages are not created equal.Some Can use the components of the other languages,some can use the classes produced in other languages to create objects,and some languages can extend the classes of other languages using the inheritance features in .NET
13
Benefits Of The .NET Approach
Simple and faster systems development
Rich object model
Enhanced built-in functionality
Many different ways to communicate with the outside world
Integration of different languages into one platform
Easy deployment and execution
Wide range of scalability
Interoperability with existing applications
Simple and easy-to-build sophisticated development tool
Fewer bugs
Potentially better performance
14
15
Contents1.Classic ASP
1.1 Classic ASP Success/Demerits
1.2 A New Asp.Net Era
2.System Architecture
2.1 Application Architecture overview
2.2 Building a 3-Tier Architecture
2.3 Asp.Net Web Application Architecture
3.Asp.net features
4.Asp.Net Web Pages
4.1 Asp.Net Web Form
4.2 Event Flow
4.3 Asp.Net code Changes
5.Asp.Net Execution
5.1 Asp.Net Execution Model
5.2 Compilation and Execution
5.3 Multimedia Execution
16
“Classic” ASP Successes
• Simple procedural programming model
• Access to COM Objects– ADO– File system object
• No compiling, just save• Support for multiple
scripting languages• Mix HTML and code• VBscript – leverage Visual
Basic skills
•Tied tightly into IIS
•Not Really Cross-platform–Solutions exists for Apache & Linux
•Not easy to implement
•Can only use Visual Basic or Java
•Script Language – must be interpreted
“Classic” ASP Demerits
17
“Classic” ASPChallenges
• Code readability
• Coding overhead
• Post Back complexity
• Reuse
• Performance
• DLL locking
• Deployment
• Sessions
• Caching
18
System Architecture?System Architecture?
A New Era – ASP.NET
• A complete rewrite of the original ASP– Kept the best concepts from ASP
• your code from the HTML– Separates the programming logic from the look of the page– Program in ANY
.NET language– Better tools, debugging
• Pre-fabricated controls– Similar to Windows controls
• Built-in security mechanisms• session management• Just-in-time compilation
– No server restarts required• Settings stored in XML
Its mainly based on the 3-Tier System Architecture
19
Single tier Architecture
Presentation,Business logic and data logic all are present in the same layer,which normally runs on a stand-alone system.e.g., C,C++ applications.
Two tier Architecture
Presentation and business logic will be present in one layer and data logic will be available in a separate layer.Example: Client-Server application.
Three-tier Architecture
Presentation,Business logic and data logic all are present in different layers.Asp.Net are developed using 3-tier architecture.
N-tier Architecture
Presentation,Business logic and data logic all are present in different layers.Business logic may present in multiple layers. Web Applications using external services are developed using n-tier architecture. E.g. Remoting and web services ( Weather forecasting ).
System Architecture
20
Distributed
Business Logic
Presentation
Data
Three-Tier
Data
Business Logic
Presentation
Data
Business Logic
Presentation
Monolithic
Business Logic
Presentation
Data
Client/Server
Data
Presentation
BusinessLogic
Application Architecture overview
Click Here To Enlarge
21
Building a 3-Tier Application
Presentation Tier
This Tier is responsible for communication with the users and web service consumers and it will use objects from Business Layer to response GUI raised events.
Logical Tier
This is the brain of the 3-Tier Application. Some architects do not make any distinction between Business Tier and Data Access Tier.
Some of the advantages are
Increases code transparency Supports changes in Data Layer. You can change or alter database with out touching the Business Layer and this would be a very minimum touch up.
Data Tier
This Tier is responsible for retrieving, storing and updating the Information therefore this tier can be ideally represented through a commercial database. We consider stored procedures as a part of the Data Tier. Usage of stored procedures increases the performance and code transparency of an application.
22
ASP.NET Web Application Architecture
Presentation TierPresentation Tier
Business Logic TierBusiness Logic Tier
Data TierData Tier
Graphic Files
Graphic Files
UI Pages(.htm)
UI Pages(.htm)
XML Web Services(.asmx)
XML Web Services(.asmx)
User Controls(.ascx)
User Controls(.ascx)
Code-Behind File(.aspx.vb or .aspx.cs)
Code-Behind File(.aspx.vb or .aspx.cs)
ProxyProxy ADO.NETADO.NET
.NET Objects.NET
Objects
Data Source
COM+ServicesCOM+
ServicesCOM
ObjectsCOM
Objects
RCWRCW
Web Form (.aspx)
Web Form (.aspx)
23
ASP .NET Features
ASPX, ASP – side by side
Simplified programming model
Simplified deployment
Better performance
Caching
Security
Powerful controls
Simplified browser support
Simplified form validation
Code behind pages
More powerful data access
Web services
Better session management
No DLL locking
No DLL registration
Simplified configuration
Page lets
24
What Is a Web Form?
.aspx extension
Page attributes
@ Page directive
Controls save state
Body attributes
Form attributes
<%@ Page Language="C#" Inherits=Project.WebForm1 %><html>
<body ms_positioning="Grid Layout">
<form id="Form1" method="post" runat="server">
</form></body>
</html>
<%@ Page Language="C#" Inherits=Project.WebForm1 %><html>
<body ms_positioning="Grid Layout">
<form id="Form1" method="post" runat="server">
</form></body>
</html>
Enlarge
Enlarge
25
Event flow in ASP.NET pages Event flow in ASP.NET pages (.aspx)(.aspx)
– Application Level Events (Global.asax)– Page_Init: page and controls are initialized – Page_Load: all the controls and page are loaded– Change events for controls are processed– Click events for controls are processed– Page_PreRender: page is about to render– Page_Unload: page is unloaded from memory
The Page Directive
Defines page-specific (.aspx file) attributes used by the ASP.NET page parser and compiler.
Example showing an .aspx page mapped to its code behind:
<%@ Page Codebehind="WebForm1.aspx.vb"
inherits="AspNet.WebForm1" %>
26
ASP.NET Coding Changes
• Page directives– Language attribute must be in set the @Page directive
• Structural changes
– All functions and variables must be declared within a <script> block
– Only one language per page– Render Functions are no longer supported; use
Response.Write
• Design-Time controls are no longer supported
– Replaced with Web controls
27
Visual BasicVisual BasicSource Source codecode
CompilerCompiler
C++C++C#C#
CompilerCompilerCompilerCompiler
AssemblyAssemblyIL CodeIL Code
AssemblyAssemblyIL CodeIL Code
AssemblyAssemblyIL CodeIL Code
Operating System ServicesOperating System Services
Common Language RuntimeCommon Language Runtime
JIT CompilerJIT Compiler
Native CodeNative Code
ManagedManagedcodecode
UnmanagedUnmanagedComponentComponent
ASP.NETExecution Model
28
ASP.NET Runtime Compilation and Execution
Nativecode
C#Visual Basic .NET
language Which?
Visual Basic .NETcompiler
C#compiler
MSILJIT
compiler
default.aspx
Common Language Runtime
HTM
L
29
Multimedia: ASP.NET Execution Model
30
31
Contents
1.Introduction to Control
1.1 Web form Vs HTML Controls
1.2 Server Control
1.2 Maintaining the state in Server Control
1.3 How to Open The Application?
2.Toolbox and its control types
2.1 HTML Controls
2.2 Web form Control
2.3 Validation Control
2.3 List Control
2.4 Component
2.5 Data Control
32
Introduction Controls
Types
• Web Form Controls As Sever controls
• Textbox, Label, Hyperlink, Etc
• Dropdown List, Data Grid, Data List, Etc
• HTML Controls (Client or Server)
• ADO.NET Design Controls(Data Controls)
• System Components
• Validation Controls
An ASP.NET control that helps you to transfer data between a dialog page and its invoker page.
Properties window
Controls
33
Web Form Vs HTML Controls
Both have the following benefits
– An object model that you can program against on the server
– A set of events for which you can write sever side event handlers.
– The ability to handle events in client script .
– Automatic maintenance of the control's state (View State).
– Interaction with validation controls so you can easily verify that a user has entered
appropriate information into a control.
– Data binding to one or more properties of the control.
– Support for HTML 4.0 styles if the Web Forms page is displayed in a browser that supports cascading style sheets.
– Pass-through of custom attributes.
34
What is a Server Control?
• Runat="server"– Event procedures run on the server– View state saved
• Properties and methods are available in server-side event procedures
<asp:Button id="Button1" runat="server" Text="Submit"/><asp:Button id="Button1" runat="server" Text="Submit"/>
private void btn_Click(object sender, System.EventArgs e)
{lblName.Text = txtName.Text;
}
private void btn_Click(object sender, System.EventArgs e)
{lblName.Text = txtName.Text;
}
•Without code
–Required field
–Within range
–Two fields equal (password)
–Regular expressions
–Validation error messages
•With code, but simplified
–Custom validation
35
Maintaining the State of ASP.NET Server Controls
• Server control state is stored in __VIEWSTATE, a hidden control on the Web Form
• VIEWSTATE stores state in a string value of name-value pairs
<form id="Form1" method="post" runat="server"> <input type="hidden" name="__VIEWSTATE"
value="dDw3NzE0MTExODQ7Oz4=" /> 'HTML here</form>
<form id="Form1" method="post" runat="server"> <input type="hidden" name="__VIEWSTATE"
value="dDw3NzE0MTExODQ7Oz4=" /> 'HTML here</form>
On by default, adjustable at Web Form and control level
<%@ Page EnableViewState="False" %><%@ Page EnableViewState="False" %>
<asp:ListBox id="ListName" EnableViewState="true" runat="server"> </asp:ListBox><asp:ListBox id="ListName" EnableViewState="true" runat="server"> </asp:ListBox>
36
Choose The Application what ever u want create
Visual C# Projects—Asp.Net Web Application
37
Open The Web formTask Bar
Toolbox
Web Form
Properties Window
Solution Explorer
38
HTML Coding
Enlarge
39
Code-Behind
Enlarge
40
Toolbox:It Contains Collection of components or controls
Using Tools:
1.Just Drag And Drop in the Web form
Asp.Net Toolbox:
1.Web Forms-General Server Controls
2.Data Controls:Used For Connectivity
3.HTML Controls-As Like General controls like Textbox and Label etc..
Toolbox
41
42
HTML Controls
HTML Controls:
•This Control used general what we used before in html.
•Here the control is not called as Server Control
•While using this HTML Control we should convert as Server Control in our ASP.Net Application
<DIV style="DISPLAY: inline; HEIGHT: 15px"ms_positioning="Flow Layout">Label</DIV>
HTML Coding
43
Converting HTML Control to Asp.Net Sever Control Control
Drag and Drop the html control in web form
Select the control
Right Click the control and mark as “Run As Server Control”
Now the control changed as Server Control
<DIV style="DISPLAY: inline; Z-INDEX: 101; HEIGHT: “76px"ms_positioning="Flow Layout" id="DIV1" runat="server">Label</DIV>
HTML Control convert as Server Control
44
45
Web Controls(As Server Controls)
Web Form Controls
General ControlsList Controls Validation Controls
Ex:Textbox,Radio Button Ex:Data Grid,Data list
Ex:Required Field,Range Field, Compare Field
46
General Controls
This Control is used for general purpose as like inserting and updating
Ex:Label,Textbox,Dropdown List etc..
47
•Single-General
•Multiple-When More Number of values entered (ex:Address)
•Password-When We enter password character(ex:**** )
To Set Maximum Length For a control(ex:if set 10 it allows 10 characters only)
TEXTBOX:Its mainly used for getting input values from the users
In Coding:
TextBox1.Text=“hay”;
Id for textbox control(ex:txtename)
48
Label:Its mainly used for give identification(ex:a book having label)
Set id for the label(lblename)
Set Font Style for the Control(ex:bold)
Set some text for label(ex:Enter Ename)
Coding:
Label1.Text=“hay”;
49
Button:It used to perform some Action as like event(ex:Button Click)
Button ID
Enter Some Text for Button
Set some styles for Button
Events for button
50
Link Button:Its used redirect one page to another page
Id for Link Button
Enter some text for Link Button
Using response object the page should be redirected
51
Image Button:As Like Button control with some images
Id For imagebutton(ex:imgbtn)
Browse the image and select it
Set some alternative messages for image
When image button is clicked the textbox shoes the messages
52
Dropdown List:Adding multiple values(Ex:Date Of Birth)
The is First way adding value in control (Dropdown-properties-items-collection-set text-Add-ok)As shown in fig(Ex:Month in DOB I.e Constant string Values)
The second way adding value is coding as shown(ex:numeric values-day&month in DOB)
53
List Box:Adding Multiple values with multiple selection
1.Single:For selecting single value
2.Multiple:For selecting more than one using Ctrl Key
1.Adding values in List Box (List Box -properties-items-collection-set text-Add-ok)ex:Select More than area
Coding used for select the values from the control
54
Hyperlink:Make a link to next page
This is to link one page to other page(Browse the url and select it)
Text for hyperlink control
55
Checkbox List:Its used to check more than one value from the control
This for selecting the value from the control.
Adding values through collections
For selecting more than one values we should do for loop to make of multiple values
56
Radio Button List:Its used to select the single value from the control
As like other controls its also used add values in collections.In This control is used select the particular or singular value at a time.
Ex:Select the Gender(male or Female)
Display values as vertical
This for selecting the value from the control.
57
Calendar:Display the current calendar in specified formats
Represents the style for calendar control
Getting values from the calendar control
58
59
Validation Controls
•The validation control is used to check some condition for the control.
•This control is activate as Server Control
60
Control Name Description
RequiredFieldValidator Ensures that the user does not skip an entry.
CompareValidatorCompares a user's entry with a constant value or a property value of another control using a comparison operator (less than, equal to, greater than, and so on).
RangeValidator
Checks that a user's entry is between specified lower and upper boundaries. You can check ranges within pairs of numbers, alphabetic characters, or dates. Boundaries can be expressed as constants.
RegularExpressionValidator
Checks that the entry matches a pattern defined by a regular expression. This type of validation allows you to check for predictable sequences of characters, such as those in social security numbers, e-mail addresses, telephone numbers, postal codes, and so on.
CustomValidatorChecks the user's entry using validation logic that you code yourself. This type of validation allows you to check for values derived at run time.
Validation Summary Displays the validation errors in summary form for all of the validators on a page.
61
RequiredFieldValidator:Its is used to validate the function must to enter the field.Ex:Mandatory
Textbox
Required Field Validator control
Specified which control to be validate(ex:Textbox1)
Enter some error message that should displayed
62
CompareValidator:This used to compare two values should be same or not.
Ex:Compare new and confirm Password
Specify which control to compare
Specify which control to validate
Enter some messages to displayed
63
RangeValidator:Check the range value(Ex:Minimum and Maximum value)
Specify which control to validate
Enter The minimum range value
Enter the maximum range value
64
Validation Summary:Its display the full error summary (Ex:yahoo new user registration form)
Select whether the the summary should be shown are not
For displaying error message format
65
RegularExpressionValidator:Its used to specify some expressions as like email,phone numbers
Enter the some error message
In validation Expression select some expression what u need
66
67
List Controls
The List controls belongs to web controls..The controls are
1. DataGrid
2. DataList
3. Repeater
These controls are used select single/all the values from the database and display with some style formatting
68
Data Grid
Displays data as a table
Control overAlternate itemHeaderFooterColors, font, borders, etc.Paging
Updateable
Item as row
Data grid contains auto format to display the grid effectively,For these Data Grid->Right Click->Auto Format->Select the style formats as our wish
69
Data Grid
In Columns it contain
Bound Column
Used to Give valid Column Name
Button Column
In-built button like edit,cancel,select
Hyperlink
Give Link to other Page
Template Column
Add extra column ex:check box
In the data Grid we can set paging,sorting and column designing using the Data Grid->Right Click->Property Builder->Columns
Data grid get source from dataset
70
Data ListData List controls should as like data grid but without in-built button column
•Directional rendering
•Good for columns
•Item as cell
•Alternate item
•Updateable
Styles:
In Data List it contains some pre-defined styles and alternating styles for display.
In These every thing should be included in <item template>
We can set the styles in HTML with tags or else dragging controls in <item template>
71
Data List
For Binding values in data grid
Its also take source from the dataset
In Code-Behind Page_Load()
In HTML Page
In HTML page the column values should bind inside the item template tag and with other tags ex:table,label etc..
72
Repeater
The repeater control is static one and does not have any user interfaces
List format
No default output
More control
More complexity
Item as row
Not updateable
In HTML
Compare to data list control it have only limited formatted style
73
RepeaterIn Web Form Page_Load( )
In HTML Page
As like other List Control it take source from Dataset
The column value should bind inside in item template and with data binder tag
74
components
The components are used add some functionality built –in as component Ex:Timer
75
76
Data Controls
•ConnectionConnection
•CommandCommand
•DataReaderDataReader
•DataSetDataSet
•DataAdapterDataAdapter
•DataViewDataView
77
Data Controls
AuthorsAuthorsAuthorsAuthorsConnectionConnection
DatabaseDatabase
DataAdapterDataAdapter
DataSetDataSet
Select … from AuthorsSelect … from Authors
AuthorsAuthors
78
Data Controls
PublishersPublishersPublishersPublishersConnectionConnection
DatabaseDatabase
DataAdapterDataAdapter
DataSetDataSet
Select … from PublishersSelect … from Publishers
AuthorsAuthors
PublishersPublishers
79
Data Controls
DatasetDataset
AuthorsAuthors
PublishersPublishers
Data ViewData View
Data GridData Grid
Data ListData List
RepeaterRepeater
80
81
Contents
1. Into to State Management
2. Client State Management
1.1 Cookies
1.2 Query String
1.3 View State
3. Server State Management
3.1 Application
3.2 Session
3.3 Database Support
82
Introducing State Management
State Management is a process of maintaining in application and session-related information when multiple users request for the same or different web pages of an Asp.Net application.
State Management needed when the same user logs on to a web site for multiple times.
In addition ,state management includes maintaining page-level information during the round trip of a Web Form page.
Types
1.Client Side Management
2.Server Side Management
83
State Management Types
1.Client side Management
• View State
• Cookies
• Query Strings
2.Server side Management
• Application
• Session
• Database Support
84
View stateThe View state in an Asp.Net Web Form enable to retain page and control-specific values between round trips.Each web form and the controls on the page have the view state property that is inherited from the base control class.Asp.Net Frame work uses the view state property to automatically save the values of the page and each control prior to rendering the page.
The view state is implemented with a hidden form field called _VIEWSTATE,which is automatically created in every web form .When Asp.Net executes a web page on a web server ,the values stored in the view state property of the page and controls on it are collected and formatted into a singe encoded string.The encoded string is then assigned to the value attribute of the hidden form field _VIEWSTATE and is sent to the client as a part of the web page.When the page is posted back to the server,the Asp.Net Framework parses the view state string at page initialized and restores the property information in the page
By default the view state is enabled ,if we need we can disabled for a particular control.
Advantages:
The view state stored in a standard HTML format as a part of the web page.
Easy to implement
The Values in view state are hashed,compressed and encoded for Unicode implementation
Disadvantages
Page speed is slow when datas are high
Security Less
•A cookie is a small file that the server embeds on the user's computer .Each time the same computer requests a page with a browser, it will send the cookie too.Cookies can be either temporary or persistent.temporary cookie is exist in memory space of a browser,when the browser is closed,all the temp cookies lost.A persistent cookie is saved as a text file in the file system of the client computer.
•Benefits Of Cookies
•No server resources are required as they stored in client•They are light weight •Simple to use
Limitations Of Cookies
Most Browsers place a 4096-byte limit on the size of a cookie,although support for 8192-byte cookie is becoming more common in the new browser and client-device versions available today.•Some users disable their browser or client device’s ability to receive cookies,thereby limiting the use of cookies•Cookies can be tampered and thus creating a security hole.•Cookies can expire thus leading to inconsistency
Cookies
Query String Benefits
•When we need to submit information back to a web page or another page by using URL .A query string provides a simple way to pass information from one page to another page.
•The Query String is used to store and transfer the information through the URL.
•It get the values from the Request Object.
•No server resources are required.This query string containing in the HTTP requests for a specific URL
•All browsers support query strings
Query String Limitations
•Query String data is directly visible to user thus leading to security problems
•Most browsers and client devices impose a 255-character limit on URL length.
87
SessionSession State is a collection of objects that are stored in the memory of the web server.
But where is the Session State stored?
In II5, Session State is stored in the memory of the process aspnet_wp.exe. In IIS6, by default all applications share the same application pool, i.e. the session state is stored in the memory of the process w3wp.exe
The advantages of using session state are as follows:
· Process independence
· Ease of implementation
· Durability
· Scalability
The disadvantages of using session state are:
· Low Performance for large volumes of data
· Overhead involved for serializing and de-serializing the Session data
Session state in ASP.NET can be stored in one of the following three ways.
• InProc
• State Server
• SQL Server
88
Asp.Net provides state as means of storing global application-specific information in the application state is is stored in a key-value pair and is used to maintain data consistency between server round trips and between pages.
•The Application object is used to store and access variables from any page, just like the Session object.
•The difference is that ALL users share one Application object, while with Sessions there is one Session object for EACH user.
• The Application object should hold information that will be used by many pages in the application
•Application variables can be accessed and changed by any page in the application.
•You can create Application variables in "Global.asax"
Application
Database support is used to combination with cookies or session state.For ex,for an e-commerce web site ,you can maintain state information by using a relational database.
Advantages
1. Security
2. Consistency
3. Personalization
Disadvantages
1. Data base for state management involves complex hardware and software configurations
2. The web site may go down poor construction of the relational data model that is used to support session state in a web application.
Database support
90
91
Contents
1.Page And its Life Cycle
2.Request And Response
3.Session And Application
4.Demo:Using the objects in
application
92
Page Life Cycle
Page_Init:
During this event, you can initialize values or connect any event handlers that you may have.
Page_Load:
During this event, you can perform a series of actions to either create your ASP.NET page for the first time or respond to client-side events that result from a post. The page and control view state have been restored prior to this event. Use the IsPostBack page property to check whether this is the first time that the page is being processed. If it is the first time, perform data binding. Also, read and update control properties.
Page_DataBind:
The DataBind event is raised when the DataBind method is called at the page level. If you call DataBind on individual controls, it only fires the DataBind event of the controls beneath it.
Page_PreRender:
The PreRender event is fired just before the view state is saved and the controls are rendered. You can use this event to perform any last minute operations on your controls.
Page_Unload: After a page has finished rendering, the Page_Unload event fires. This event is a good place to perform final cleanup work. This includes items such as the cleanup of open database connections, discarding objects, or closing those files that are open.
93
Response and Request objects
• Response
Response object is used to send output to the user from the server – Represents the client browser– Response.Redirect(“Webform2.aspx”)– Response.Cookies[“Username”] = “Bob”
• Request
Request object is used to get information from the user– Represents the server– Request.PhysicalApplicationPath– Username = (String)Request.Cookies[“Username”]
94
Session and Application variables
Session variables
– Hash table-style collection of name-value pairs– Remembered until the client closes the browser (or the session
timeout expires – default 20 minutes)– Only for one client– Session[“Valid User”] = true
Application variables
– Hash table-style collection of name-value pairs– Always remembered– For all clients– Application[“NumClients”] = NumClients + 1
95
96
Open The Asp.Net Web Application And Choose the Web Form
Webform1
97
Create Table And Place The Controls
Tables $Controls
98
In Code-Behind Write Coding For Creating Cookies,Session And Query String
Session
Cookies
Query String
99
Select the Another Web Form And Place The Controls
100
In WebForm2 Code Behind Write the coding how to retrieving the values from cookies,session and Query String
Session
Cookies
Query String
101
Type The Values As 98,99 how it transform to next page
102
Ya ..Now it Get Back The values From First page Using These Objects
103
Create Web form And write in page_load( ) event application Object
Application
Object
104
In First time the count shows 1
105
After Refreshing the the page the count should be increased(Now its 3)
Enlarge
106
107
Contents
1. Global.Asax File
1.1 Global Programming
2. Web.Config file
2.1 Session Variables
3. Business Objects
108
ASP.NET Web Applications
• Global ASAX
– Application_Start– Application_End– Session_Start– Session_End
• Session
• Application
109
Global Programming (Global.asax)
• Define Application Global methods, constants, variables
• Global Event Handling
– Application_Start
– Session_Start
– Application_Begin Request
– Application_Authenticate Request
• Useful for setting up custom Page.User and roles
– Application_Error
– Session_End
– Application_End
110
The Web.config file
• Configuration management for ASP.NET• XML file• Hierarchical structure
Master systemMaster systemmachine.configmachine.config
App A web.configApp A web.config App B web.configApp B web.config
App B subdirApp B subdirweb.configweb.config
111
web.config
• Site configuration file
• Like an .INI file for your site
• XML format
• Extensible
• Some settings
– Security– Session– Localization– Tracing– Debugging
112
Session Variables
• Store state information
• No longer require cookies
• Share between servers
<sessionState mode=“StateServer“stateConnectionString="tcpip=127.0.0.1:42424"sqlConnectionString="data source=127.0.0.1;user id=sa;password="cookieless="false" timeout="20"
SessionState/>
113
Business Objects
• Not registered
– Placed in ./bin directory
• Not locked
– Shadow copy
114
115
Contents
1.Introduction about Assembly
2.Assembly Architecture
3. Manifest Functions
4. Single/Multi File Assembly
5.Assembly Types
5.1 Private Assembly
5.2 Public Assembly
5.3 Global Assembly Cache
6.Assembly Location
116
ASSEMBLY
Assemblies are the building blocks of .NET Framework applications
It form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions.
An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality.
An assembly provides the common language runtime with the information it needs to be aware of type implementations.
Assemblies can be static or dynamic.
Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in portable executable (PE) files.
Dynamic assemblies are run directly from memory and are not saved to disk before execution. Dynamic assemblies are stored on the disk after they have executed.
117
ASSEMBLY Architecture In general, a static assembly can consist of four elements:
The assembly manifest, which contains assembly metadata.
Type metadata.
Microsoft intermediate language (MSIL) code that implements the types.
A set of resources.
An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes.
The assembly manifest can be stored in either a PE file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a standalone PE file that contains only assembly manifest information.
Assembly Metadata
Metadata
MSIL
Resources
118
MANIFEST FUNCTIONS:
Assembly Metadata is stored in Manifest contains all the Metadata needed to do the following things
• Version of assembly• Security identity • Scope of the assembly• Resolve References to resources and classes
ASSEMBLY BENEFITS
Enable developers to specify version rules between different software components. Provide the infrastructure to enforce versioning rules.
Provide the infrastructure to allow multiple versions of a component to be run simultaneously (called side-by-side execution).
NAMESPACE:
System.Reflection Namespace
System.Reflection namespace contains classes and interfaces that provide a managed view of loaded types, methods, and fields, with the ability to dynamically create and invoke types.
119
SINGLE-FILE ASSEMBLY
Group all elements in a single physical file
MULTIFILE ASSEMBLY
The elements of an assembly can be contained in several files. These files can be modules of compiled code, resources (such as .bmp or .jpg files), or other files required by the application.
Assembly Manifest
Type Metadata
MSIL code
Resources
Assembly Metadata
Type Metadata
MSIL code
Type Metadata
MSIL code
MSIL code
120
ASSEMBLY TYPES
There are Two types
Private Assembly Public Assembly
PRIVATE ASSEMBLY:
•A Private assembly is normally used by single application, and is stored in the application’s directory or a sub directory
PUBLIC ASSEMBLY:
•A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime.
•Shared assemblies are usually libraries of code Ex: Crystal report classes – used by all application for Reports
121
GLOBAL ASSEMBLY CACHE
•GAC is used where shared .NET assembly reside.
•GAC is used in the following situations
•If the application has to be shared among several application\
•If the assembly has some special security requirements like only administrators can remove the assembly.
•If the assembly is private then a simple delete of assembly the assembly file will remove the assembly
ADD AND REMOVE AN ASSEMBLY FROM GAC
gacutil [options] [assemblyName | assemblyPath | assemblyListFile]
assemblyName
The name of an assembly. You can supply either a partially specified assembly name such as myAssembly or a fully specified assembly name such as myAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0038abc9deabfle5.
122
assemblyPath
The name of a file that contains an assembly manifest.
assemblyListFile
•The path to an ANSI text file that lists assemblies to install or uninstall.
•To use a text file to install assemblies, specify the path to each assembly on a separate line in the file. The tool interprets relative paths, relative to the location of the assemblyListFile.
•To use a text file to uninstall assemblies, specify the fully qualified assembly name for each assembly on a separate line in the file.
Examples
The following command installs the assembly mydll.dll into the global assembly cache.
gacutil /i mydll.dll
The following command removes the assembly hello from the global assembly cache as long as no reference counts exist for the assembly.
gacutil /u hello
For example, if both version 1.0.0.0 and 3.2.2.1 of hello are installed in the cache, the command gacutil /u hello removes both of the assemblies.
123
Use the following example to avoid removing more than one assembly. This command removes only the hello assembly that matches the fully specified version number, culture, and public key.
gacutil /u hello, Version=1.0.0.1, Culture="de",PublicKeyToken=45e343aae32233ca
Strong-Name Assemblies
•Strong name is similar to GUID (It is supposed to be unique in space and time) in COM components.
•Strong name is only needed when we need to deploy assembly in GAC.
•Strong names helps GAC to differentiate between two versions.
Sn.exe –k “C:\test.snk”
124
ASSEMBLY LOCATION
An assembly's location determines whether the common language runtime can locate it when referenced, and can also determine whether the assembly can be shared with other assemblies. You can deploy an assembly in the following locations:
The application's directory or subdirectories.
• This is the most common location for deploying an assembly. • The subdirectories of an application's root directory can be based on language or culture. • If an assembly has information in the culture attribute, it must be in a subdirectory under the application directory with that culture's name.
The global assembly cache.
• This is a machine-wide code cache that is installed wherever the common language runtime is installed. • In most cases, if you intend to share an assembly with multiple applications, you should deploy it into the global assembly cache.
On an FTTP server.
• An assembly deployed on an FTTP server must have a strong name; you point to the assembly in the code base section of the application's configuration file.
125
126
Contents
1. Caching Introduction and its Types
2. Output caching
3. Fragment Caching
4. Data Caching
4.1 Cache APIs
4.2 Adding Items to cache
4.3 Cache.Add Method
4.4 Parameters
5. Additional Caching Features
5. Caching Features in .Net 1.1
127
CACHING
DEFINITION
Caching involves temporarily storing the frequently used data for the Web application on local hard disks for later retrieval. As a result, the web server on which the application resides processes requests for the Website only once and caches the requests for future. Any subsequent requests are processed from the cache instead of the Webserver.The data can be cached either at the client side or at the server side.
• Client
The data is stored in temporary files on the hard disk or in memory of the clients computer.
• Server
Microsoft Proxy Servers are generally used for caching.
ASP.NET has a powerful, easy-to-use caching mechanism that allows you to store objects that require a large amount of server resources to create in memory. It is implemented by the cache class.
• The Cache class has been designed for ease of use. By using keys paired with values, you can place items in the Cache and later retrieve them.
• when system memory becomes scarce, the cache automatically removes seldom used or unimportant items to allow memory to be used to process a high volume of requests. This technique is called scavenging.
128
1.OUTPUT CACHING
Output caching allows you to store the results that a dynamic page generates. On subsequent requests, the cached output is used to satisfy the request rather than dynamically executing the page code. Output caching is also referred to as page caching.
The following sample illustrates how to cache the output of the page for 30 seconds:
Visual C# .NET Sample
<%@ Page Language="C#" %>
<%@ OutputCache Duration="30" VaryByParam="*" %>
To use the @ OutputCache directive to control page output caching, you simply add the directive to the top of the page. The Page.InitOutputCache method translates the directive into HttpCachePolicy class methods.
The @ OutputCache directive includes the following attributes and settings:
Duration:
This attribute specifies how long an item is held in the cache. The value for Duration is listed in seconds.
VaryByParam:
This attribute determines cache entries by Get or Post parameters.
For example, if a QueryString variable named testVal is set for the VaryByParam attribute, every page request that contains a different value for testVal is cached in a separate page.
129
@ OutputCache directive contains a Location attribute.
This attribute determines the location for cached item. You can specify the following locations:
Any
This stores the output cache in the client's browser, on the proxy server (or any other server) that participates in the request, or on the server where the request is processed. By default, Any is selected.
Client
•This stores output cache in the client's browser.
Downstream
•This stores the output cache in any cache-capable devices (other than the origin server) that participate in the request.
Server
•This stores the output cache on the Web server.
None
• This turns off the output cache.
Visual C# .NET Sample
<%@ Page Language="C#" %>
<%@ OutputCache Duration="30" VaryByParam="*" %>
Output caching
130
2.FRAGMENT CACHING Fragment caching is useful when you need to cache only a
subset of a page. This is accomplished by caching the outputs of a user control. Navigation bars, headers, and footers are good candidates for fragment caching.
• The fragment caching is implemented through User Controls.
• The fragments of the page that will be cached are placed in one or more User Controls.
•The User Controls are then included in different pages as desired.
• The caching options for the controls are specified by placing an OutputCache directive within each control or programmatically in the code behind using the PartialPageCachingAttribute.
•The caching parameters are set on the individual controls rather than within the page itself.
•The User Controls are then cached independently according to each directive, while the remainder of the page content remains dynamic and uncached.
131
3. DATA CACHING
Data caching is where the majority of the control is handled programmatically.
The Cache class located in the System.Web.Caching namespace is the way in which items are added into and retrieved from the ASP.NET cache.
It is relatively straightforward to use in your Web applications.
The Cache class provides a dictionary type interface, which means you assign a key to the value when it is stored.
The key is used to access the value again at a future point in time when it is needed.
1.Using a name value pair similar to a Dictionary object.
Example: Cache[“keyName”] = “MyValue”; Example: Cache[“keyName2”] = myObject;
132
2.Using the Cache.Add method, which returns an object representing the item added into the cache. If an object with the given key name already exists in the cache, then the Add method will fail.
Example: Cache.Add(“keyName”, “MyValue”); Example: Cache.Add(“keyName2”, myObject);
3. Using the Cache.Insert method, which, unlike the Insert method, does not have a return type. In addition, if an item already exists in the cache with the given key name, the Insert method will override it with the new value given.
Example: Cache.Insert(“keyName”, “MyValue”); Example: Cache.Insert(“keyName2”, myObject);
DATA CACHING Example
133
CACHE APIS
Cache Application Programming Interfaces (APIs) allow you to programmatically store arbitrary objects to memory so that your application can save the time and resources that it takes to re-create them.
Cache APIs allow you to expire items from the cache based on the following credentials:
•Time
•File dependencies
•Cache key dependencies
The Cache class has been designed for ease of use. By using keys paired with values, you can place items in the Cache and later retrieve them.
You can instruct the Cache to give certain items priority over other items when it performs scavenging. To indicate that a specific item is of greater or lesser importance than another, specify one of the CacheItemPriority enumeration values when you add an item using the Cache.Add method or Cache.Insert method.
134
ADDING ITEMS TO THE CACHE
There are three different techniques you can use to add an item to the Cache object. If you want to take advantage of the scavenging, expiration, and dependency support offered by the Cache, you must use either the Cache.Insert method or the Cache.Add method.
Cache.Insert Method (String, Object)
Inserts an item into the Cache object with a cache key to reference its location and using default values provided by the CacheItemPriority enumeration
[C#]
publicvoid Insert( string key, object value );
PARAMETERS
key
The cache key used to reference the item.
value
The object to be inserted into the cache.
The following example demonstrates how to insert an item into an application's cache.
[C#]
Cache.Insert("DSN", connectionString);
135
PARAMETERS
key
The cache key used to reference the item.
value
The item to be added to the cache. dependencies
The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this paramter contains a null reference.
absoluteExpiration
The time at which the added object expires and is removed from the cache.
slidingExpiration
The interval between the time the added object was last accessed and when that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed.
priority
The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost.
onRemoveCallback
A delegate that, if provided, is called when an object is removed from the cache. You can use this to notify applications when their objects are deleted from the cache.
136
CACHING FUNDAMENTALS IN ASP.NET FRAMEWORK 1.1Cache
• A static object with a collection dedicated to storing and processing cache information (System.Web.Caching.Cache).
Cache Dependency
• It is a mechanism through which the cache data can be made dependant on any file or a key data present in the cache itself.
Cache Expiration
• It provides a way to provide expiration to the data available in the cache.
Cache Callback
•: It is a delegate, which can be associated with any cache item. It is invoked when the associated item in the cache expires due to any reason.
The expiration reasons can be any of the following
1. Removed: The item is explicitly removed from cache.
2. Expired: The item’s time is expired due to cache time out or its own expiration policy settings.
3. Underused: The cache item is removed from the cache due to shortage of resources.
4. Dependency Changed: The cache item is removed from the cache because its dependency has been changed.
137
138
Contents
1.Authentication
1.1 Authentication Options
1.2 Form Authentication
1.3 Demo
2.Authorization
139
AUTHENTICATION
THIS IS WHO I AM
Authentication is the process of deciding who can access the application. User name and Password is the most common mechanism for Authentication.
Authentication means validating a user based on set of credentials
Authorization occurs after authentication.
Ex:
such as E-mail, username, and password.
Authorization requires specifying access restrictions and permissions for your users. Hence,these terms are different but interrelated.
140
Authentication Accepted Authentication Rejected
Display Content Redirect To Registration
As you see in the above diagrams,when a user enters the application,two possible courses of action occur.
1.The user is authenticated,so the requested content is returned.
2.The user is not authenticated and is sent to a registration form.Once the registration process is successful,then and only then is the requested content returned.
141
Options Available
Forms Authentication :
Login request are made by filling form in a web page and submitting that form to the server.
Windows Authentication :
Login pages pass user credentials to a web server.The web server then handles the authentication using which ever method is configured on the virtual directory that the application is running within.
Passport Authentication :
Authentication is performed via a centralized authentication provided by Microsoft.
142
FORMS AUTHENTICATION MODEL
BROWSER SERVERBrowser sends request for page A to the server
Server refuses anonymous access and sends login page instead
BROWSER SERVER
Browser sends a login request to the server
Server authenticates and returns page A along with a cookie to the browser
BROWSER SERVER
Browser request page B and passes a copy of the cookie
Server accepts cookie and sends back page B
143
Forms authentication handles authentication using your own custom logic with an ASP.NET application.
When a user requests a page for the application, ASP.NET checks for the presence of a special session cookie.If the cookie is present,ASP.NET assumes the user is authenticated and process the request.
If the cookie isn’t present,ASP.NET redirects the user to a Webform you provide.
Forms Authentication
Using a Web.Config file
<configuration>
<system.web>
<authentication mode="Forms">
<forms name="logincookies"
loginUrl="login.aspx”
protection="All"
timeout="30“
path="/" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
Attributes Description
•Name Name of the authentication cookie
•LoginUrl The login page to which
unauthenticated users should be redirected.
•Protection Protect the authentication cookie
•Timeout The timeout value for the cookie to expire.
144
Checking the username and password through Authentication
Enter the Username And Password in
Textbox
145
The username is not valid then it display the error message
146
147
AUTHORIZATION
what I can do:
When user name and password matches it checks to see what permission you have been granted.
DEFINITION
The process of granting a user the permission to use a resource, or denying them access to a resource or a group of resources.
Coding
<authorization>
<deny users="?" />
</authorization>
148
Tag Description
Deny This can take three attributes. 1. User: User name can be particular
user name or ? Anonymous users.
2.Role: Describes particular role such as administrator.
3.Verb: set to a particular request.
Allow This can take three attributes
1. User: User name can be particular user name or ? Anonymous users.
2.Role: Describes particular role such as administrator.
3.Verb: set to a particular request.
149
150
Debugging ASP.NET
• Using Visual Studio .NET debugging tools
– Breakpoints
– Stop keyword
– System.Diagnostics.Debug
– Command/Immediate Windows
– Add Watch/Quick Watch
– Autos/Locals Windows
• Trace
• Client Script Debugging
– Active Documents
– Debugger keyword
151
152
Contents
1.Intro to Tracing
2.Page Level Tracing
2.1 Write Trace Contents
3.Application Level Tracing
3.1 Viewing Trace
153
Tracing
ASP.NET introduces new functionality that allows you to view diagnostic information about a single request for an ASP.NET page simply by enabling it for your page or application.
In order for these messages and other tracing information to be gathered and displayed, we must enable tracing for the page or application.
Trace statements are processed and displayed only when tracing is enabled. You can control whether tracing is displayed to a page, to the trace viewer, or both.
Types:
1.Page-Level Tracing
2.Application-Level Tracing
154
Page Tracing
We can control whether tracing is enabled or disabled for a page with the Trace attribute of the @ Page directive. Regardless of whether the write messages to the trace log, when you enable tracing and the page is requested, ASP.NET appends a series of tables containing performance information about the page request.
Tracing is disabled by default. If you do not include a Trace attribute in your page, trace information is not gathered, and trace statements you write do not appear on the page.
To enable tracing for a page
Include an @ Page directive at the beginning of your .aspx file. Include the Trace attribute, and set its value to true.
<%@ Page Trace="true" %>
Security Note When tracing is enabled for a page, trace information is displayed on any browser that makes a request for the page from the server. Tracing displays sensitive information, such as the values of server variables, and can therefore represent a security threat.
Page-Level Tracing
<%@ Page Language=“C#" Trace="True" TraceMode="SortByCategory" %>
155
Output For Page Info
The information of page should be
shown here
156
Writing Trace Messages
ASP.NET uses the Trace Context class to store information about a request, its control hierarchy, and trace information. The TraceContext class is
available to Web Forms pages through the Page Trace property.
Current property to access the TraceContext class. In this case, use HttpContext.Current.Trace syntax.
The TraceContext class provides two methods, Write and Warn, which allow you to write statements to the trace log. Each method is overloaded and allows you to specify a tracing category, a text message, and optional error information. The only difference between these methods is that the Warn method displays its text in red.
The first is treated as a category, which you can use to sort where your messages appear in the Trace Information table that is displayed when tracing is enabled.
The Second argument is of type Exception and contains error information for the request, if there is any.
157
Page Trace Output with Warn And Write Methods
Warn( ) Messages
Write() Messages
158
To enable tracing for an application
1. If you have not done so already, create a text file, name it Web.config, and save it to your application's root directory.
2. Between the opening and closing tags of the <configuration> element, add the opening and closing tags of a <system.web> element.
3. Between the <system.web> element tags, add a <trace> element, which is self-closing.
4. In the <trace> element, declare the enabled attribute and set it to true.
5. Declare other optional attributes to modify your application's trace behavior, as you want. For example, the following application trace configuration collects trace information for up to 40 requests and allows browsers on computers other than the origin server to display the trace viewer. <configuration>
<system.web>
<trace enabled="true" requestLimit="40" localOnly="false"/>
</system.web>
</configuration>
Application-Level Tracing
159
Viewing Trace Information with the Trace Viewer
• To view these statements and the additional trace information in the trace viewer by requesting Trace.axd from the root of your application directory.
•To enable set the pageOutput attribute to true in the Web.config file.
Traced Application Information
160
161
Contents
1. Introduction About Web Services
2. Usage Of Web Services
3. SOAP
4. WSDL And UDDI
5. Internet Towards Web services
6. Demo with illustration
162
Web Services
What are Web Services?
• Web services are application components • Web services communicate using open protocols • Web services are self-contained and self-describing • Web services can be discovered using UDDI • Web services can be used by other applications • XML is the basis for Web services
The basic Web services platform is XML + HTTP.
• The HTTP protocol is the most used Internet protocol.• XML provides a language which can be used between different platforms
and programming languages and still express complex messages and functions.
Web services platform elements
• SOAP (Simple Object Access Protocol) • UDDI (Universal Description, Discovery and Integration) • WSDL (Web Services Description Language)
163
Web services and its usesReusable application components
There are things different applications needs very often.
Web services can offer application components like currency conversion, weather reports or even language translation as services.
Ideally, there will only be one type of each application component, and anyone can use it in their application.
Connect existing software
Web services help solve the interoperability problem by giving different applications a way to link their data.
Using Web services you can exchange data between different applications and different platforms.
Web Services have three basic platform elements
These are called SOAP, WSDL and UDDI.
164
What is SOAP?
The basic Web services platform is XML plus HTTP.
•SOAP stands for Simple Object Access Protocol
•SOAP is a communication protocol
•SOAP is for communication between applications
•SOAP is a format for sending messages
•SOAP is designed to communicate via Internet
•SOAP is platform independent
•SOAP is language independent
•SOAP is based on XML
•SOAP is simple and extensible
•SOAP allows you to get around firewalls
•SOAP will be developed as a W3C standard
165
WDSL And UDDI
WSDL
WSDL is an XML-based language for describing Web services and how to access them.
•WSDL stands for Web Services Description Language
•WSDL is written in XML
•WSDL is an XML document
•WSDL is used to describe Web services
•WSDL is also used to locate Web services
•WSDL is not yet a W3C standard
What is UDDI?
UDDI is a directory service where businesses can register and search for Web services.
•UDDI stands for Universal Description, Discovery and Integration
•UDDI is a directory for storing information about web services
•UDDI is a directory of web service interfaces described by WSDL
•UDDI communicates via SOAP
•UDDI is built into the Microsoft .NET platform
166
Heading towards a new model for the Internet
Web Web ServiceService
XMLXML
““Building Block Building Block Services”Services”
Web Web ServiceService
HTMLHTML
Client Client DeviceDevice
XM
LXM
L
Client Client DeviceDevice
XMLXML
Web Web ServiceService
XML
XML
Web Web ServiceService
XMLXML
XM
LX
ML
167
Web Services
Purchase coursewarePurchase courseware
PurchasedPurchased
Designed for people to browseDesigned for people to browse
168
Web Services
Server to server is a problemServer to server is a problem
Purchase CoursewarePurchase Courseware??
169
Web Services
Server to server is a problemServer to server is a problem
Purchase CoursewarePurchase Courseware??
170
Web Services
• Allow applications to communicate across the Internet
• Platform independent
• Protocol independent
• Synchronous/asynchronous
• Stateful/stateless
• BizTalk®
• ASP.NET
171
Web Services
.ASMX.ASMX.ASMX.ASMX
Class CoursewareWebMethod
GetPricePurchase
Class CoursewareWebMethod
GetPricePurchase
172
Web Services
.ASMX.ASMX.ASMX.ASMX
TestingTesting
Courseware.asmxCourseware.asmx
Test HTML PageTest HTML Page
173
Web Services
.ASMX.ASMX.ASMX.ASMX
Courseware.asmx?WSDLCourseware.asmx?WSDL
Service Definition(XML)Service Definition(XML)
Proxy Proxy DLLDLL
Proxy Proxy DLLDLL
WSDLWSDL
174
Web Services
.ASMX.ASMX.ASMX.ASMXProxy Proxy DLLDLL
Proxy Proxy DLLDLL
Register for CourseRegister for Course Purchase CoursewarePurchase Courseware
175
176
Contents
1. Ajax Introduction
2. Ajax Transaction
3. Http Request in Ajax
4. Non-Ajax
5. Ajax Enabled
6. Using Ajax
7. Demo
177
● Asynchronous – Communication can take place with the server as the user is interacting with the page.
● JavaScript – Coding is done in JavaScript which is close to cross browser compatible
● And
● XML – The original design was for data to be passed back and forth using XML (i.e. Web Services). As we will see, there are now other methods of passing data as well.
AJAX
178
AJAX is not a new programming language, but a technique for creating better, faster, and more interactive web applications.
With AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, your JavaScript can trade data with a web server, without reloading the page
AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole pages.
With an HTTP request, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts request pages, or send data to a server in the background.
AJAX is a browser technology independent of web server software.
AJAX Transaction
179
Requests usage in AJAX
The XMLHttpRequest Object
By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded!
AJAX was made popular in 2005 by Google (with Google Suggest).
Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions.
The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, Opera 8+, and Netscape 7.
180
Web Browser
Web Serverwww.mypage.com
User http://www.myPage.com/
GET /Page
Non-Ajax
181
Non-Ajax
Web Browser(Default.aspx)
Web Serverwww.mypage.com
User Some Interaction
POST Form Variables
Refresh entire page
User views new page
182
Ajax Enabled1st part same as before
Web Browser
Web Serverwww.mypage.com
Userhttp://www.myPage.com/
GET /
Page
183
Ajax EnabledHere is the different
Web Browser(Default.aspx)
Web Serverwww.mypage.com
UserSome Interaction
Asynchronous HTTP CallbackData Chunk
Javascript updates DOM
184
Add reference ajax.dll to your project
Modify your web.config to configure IHttpHandler for Ajax.NET requests
Write your methods in C#/VB.NET and add the attribute [AjaxMethod]
Call Class1.Method1(param1, param2, callback, context); from client-side JavaScript
Using AJAX
185
Methods only get attribute, no need to implement interface or inherit from class
[AjaxMethod]public int GetAge(string username){…}
Source-code doesn‘t change if you want to use the method in server-side code
DemoMethods dm = new DemoMethods();int age = dm.GetAge(“michael“);
WebServices can be used without code change:
<script type= “text/javascript“ src=“servie1.asmx?AJAX“></script>
Using AJAX
186
Open The Web Application
In Solution Explorer choose the add reference
187
In The Add Reference box choose the AJAX dll
188
Browse the path where the Ajax.dll located
189
Add the dll to our application
190
Here the reference should added
191
192
Demo : Add two values using AJAX
193
194
195
The values Added using AJAX
196
Wow…
197