Asp Net
Asp Net
NET
1
ASP.NET
2
A platform on a platform
W eb B row ser
HTM L
M u ltim e d ia C lie n t
M P 3 /P N G /W M V
3
A new and better version of ASP
4
ASP.NET Internals
HTTP request
*.ashx ISAPI ASPNET_ISAPI.DLL ASP.NET
*.aspx
Extension ISAPI extension
*.asmx
for ASP.NET
Named Pipes pipeline
*.disco Manager
*.soap
INETINFO.EXE ASPNET_WP.EXE
HTTP runtime provided by IIS ASP.NET Worker Process
5
ASP.NET Internals
• Requests are process in the "HTTP pipeline" inside ASP.NET worker process
– Pipeline always contains HttpRuntime class
– Pipeline always contains exactly one HTTP handler object
– Modules are interceptors that can (optionally) be placed in pipeline
– HttpContext is a valuable class accessible from anywhere in pipeline
7
Programming against the HttpContext object
Imports System.Web
8
Integrated compilation support
9
Hello, World using VB.NET in an ASP.NET page
10
System.Web.UI.Page
• An .aspx file is transformed into a class that inherits from Page class
– Page class provides HTTP handler support
– Page class members are accessible from anywhere inside .aspx file
– Much of Page class dedicated to generation of HTML
– Static HTML in .aspx file becomes part of page's Render method
– Code render blocks in .aspx file become part of page's Render method
– Members defined in code declaration blocks become members of page
class
– WebForms and server-side controls build on top of Page class
architecture
11
Using reflection from an ASP.NET page
12
System.Web.UI.Page
Imports System.Web.UI
Class System.Web.UI.Page
End Class
13
Sample aspx file customizing Page
<html><body>
<h2>Customer list</h2>
<ul>
<%
'*** code render block becomes part of Render method
Dim i As Integer
For i = 0 to (m_values.Count - 1)
Response.Write("<li>" & m_values(i).ToString & "</li>")
Next
%>
</ul>
</body></html>
15
@Page Directives
16
@Page Directives
Name Description
Language Programming language to use for <%
17
Using a code-behind source file
18
ASP.NET code can be partitioned using code-behind features
<html><body>
<h3>Splitting code between a .aspx file and a .vb file</h3>
This text was generated by MyPage3.aspx<br>
<%
Dim obj As New ContentGenerator
Response.Write(obj.GetContent())
%>
</body></html>
19
ASP.NET code used as code-behind for an ASP.NET page
Namespace AcmeCorp
Public Class ContentGenerator
Function GetContent() As String
Return "This text was generated by MyLibrary.vb"
End Function
End Class
End Namespace
20
web.config
21
An example web.config file
<configuration>
<system.web>
<httpRuntime
executionTimeout="90"
maxRequestLength="4096"
/>
<pages
buffer="true"
enableSessionState="true"
enableViewState="true"
/>
</system.web>
</configuration>
22
Creating a custom HTTP handler
23
IHttpHandler is implemented by objects that service HTTP requests
Namespace System.Web
End Namespace
24
Classes that implement IHttpHandler are plug compatible
Imports System.Web
End Class
Imports System.Web
End Class
26
Debugging ASP.NET applications
27
Creating HTML-based applications
28
The "Hello world" WebForm example
<html><body>
<form runat="server">
<p><ASP:Textbox id="txtValue1" runat="server" /></p>
<p><ASP:Textbox id="txtValue2" runat="server" /></p>
<p><ASP:Button text="Add Numbers"
runat="server" OnClick="cmdAdd_OnClick" /> </p>
<p><ASP:Textbox id="txtValue3" runat="server" /></p>
</form>
</body></html>
<script runat="server">
Sub cmdAdd_OnClick(sender As Object , e As System.EventArgs)
Dim x, y As Integer
x = CInt(txtValue1.Text)
y = CInt(txtValue2.Text)
txtValue3.Text = CStr(x + y)
End Sub
</script>
29
Using code-behind inheritance
30
<%@Page Inherits="MyPageClass" Src="MyLibrary.vb" %>
<html><body>
<form runat="server">
<p><ASP:Textbox id="txtValue1" runat="server" /></p>
<p><ASP:Textbox id="txtValue2" runat="server" /></p>
<p><ASP:Button id="cmdAdd" text="Add Numbers"
runat="server" OnClick="cmdAdd_OnClick" /> </p>
<p><ASP:Textbox id="txtValue3" runat="server" /></p>
</form>
</body></html>
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
End Class 31
User versus Programmatic Interfaces
32
Web Methods
• Web services are .NET methods marked with the WebMethod attribute
– Authored like any other method you might write, with a file
extension of .asmx
– ASP.NET takes care of mapping incoming HTTP requests onto
calls on your object
– .NET provides proxy classes on the client side that make calling
web services as trivial as calling other functions
– Client-side proxy takes care of generating HTTP request to server,
and parsing response as return value
33
Web Method within a .asmx file
using System;
using System.Web.Services;
[ WebMethod ]
public int Add( int x, int y ) {
return x + y;
}
[ WebMethod ]
public int Multiply( int x, int y ) {
return x * y;
}
}
34