Beruflich Dokumente
Kultur Dokumente
NET Programming
Custom Workshop
Student Workbook
2
Microsoft | Services
TABLE OF CONTENT
3
Microsoft | Services
Slide 1: Workshop Agenda
ASP.NET programming
Custom Workshop
Slide 2
Introduction
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
4
Microsoft | Services
Slide 3
Facilities
Transport Computers
Meals Recycling
Slide 4
Workshop Overview
Workshop’s content:
Presentation
Demos
Labs
Dev team lab (we create a web site together)
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
5
Microsoft | Services
Slide 5
Course Outline
Introduction to ASP.NET
Web Pages, Master Pages and Navigation
Server Controls
ADO.NET
LINQ
AJAX
Additional Topics (e.g. State management, Caching,
Security, Performance Best Practices)
Slide 6
Setup
Software
Course Files
Classroom Setup
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
6
Microsoft | Services
Slide 7
Questions?
7
Microsoft | Services
Slide 169 - Module 1: Introduction to ASP.NET
Module 1:
Introduction to
ASP.NET
Slide 170
Overview
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
8
Microsoft | Services
Slide 171
ASP.NET
® ®
Visual Basic C++ C# JScript …
Windows
Visual Studio
ASP.NET
Forms
Slide 172
Execution Model
Source code
Visual Basic C# C++
Unmanaged
Compiler Compiler Compiler
Component
JIT Compiler
Native Code
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
9
Microsoft | Services
Slide 173
HttpContext
Global.asax
.NET Code
ASP.NET Runtime
Native Code
Host (IIS)
Slide 174
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
10
Microsoft | Services
Slide 175
Module 2:
Web Pages, Master
Pages and Navigation
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
11
Microsoft | Services
Slide 177
Overview
ASP.NET Pages
Master Pages
Navigation
Slide 178
♦ ASP.NET Pages
Introduction
Web Forms
Run Time Compilation
Page class
Page events
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
12
Microsoft | Services
Slide 179
Introduction
ASPX files
Inherits from Page class
Partial class (generated by you and ASP.NET while
compiling)
Contains Directives
Located anywhere in the page
@Assembly, @Control, @Import, @Implements, @Page,
etc.
<%@ Directive_Name attribute=”value”
[attribute=”value”.. . ] %>
Single form model
Slide 180
Web Forms
code
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
13
Microsoft | Services
Slide 181
Slide 182
Runtime Compilation
ASPX Generate
Parse Code-
Engine behind
class
Gen’d
Request ASPX Page
File Class
Instantiate
Request Compile
Response Page
DLL
Response Instantiate, Process
and Render
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
14
Microsoft | Services
Slide 183
Page class
Intrinsic Objects
Application, Cache, Request, Response, Server,
Session, etc.
Worker properties
ClientScript, Controls, ErrorPage, Form, Master,
IsPostBack, MasterPageFile, PreviousPage, etc.
Context properties
Title, ClientQueryString, ClientTarget, etc.
Metods
DataBind, RenderControl, FindControl, LoadTemplate
etc.
Slide 184
Page Events
AbortTransaction - Occurs for ASP.NET pages marked to participate in an automatic transaction when a
transaction aborts.
CommitTransaction - Occurs for ASP.NET pages marked to participate in an automatic transaction when a
transaction commits.
DataBinding - Occurs when the DataBind method is called on the page to bind all the child controls to their
respective data sources.
Disposed - Occurs when the page is released from memory, which is the last stage of the page life cycle.
Error - Occurs when an unhandled exception is thrown.
Init - Occurs when the page is initialized, which is the first step in the page life cycle.
InitComplete - Occurs when all child controls and the page have been initialized. Not available in ASP.NET 1.x.
Load - Occurs when the page loads up, after being initialized.
LoadComplete - Occurs when the loading of the page is completed and server events have been raised. Not
available in ASP.NET 1.x.
PreInit - Occurs just before the initialization phase of the page begins. Not available in ASP.NET 1.x.
PreLoad - Occurs just before the loading phase of the page begins. Not available in ASP.NET 1.x.
PreRender - Occurs when the page is about to render.
PreRenderComplete - Occurs just before the pre-rendering phase begins. Not available in ASP.NET 1.x.
SaveStateComplete - Occurs when the view state of the page has been saved to the persistence medium. Not
available in ASP.NET 1.x.
Unload - Occurs when the page is unloaded from memory but not yet disposed.
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
15
Microsoft | Services
Slide 185
Master Pages
Slide 186
Introduction
Master Page
Content Page
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
16
Microsoft | Services
Slide 187
<asp:Content
<asp:ContentPlaceHolder ContentPlaceHolderID=
ID="Main" "Main" RunAt="server" />
RunAt="server" />
</asp:Content>
Slide 188
<html>
<body>
<!-- Banner shown on all pages that use this master -->
<table width="100%">
<tr>
<td bgcolor="darkblue" align="center">
<span style="font-size: 36pt; color: white">ACME Inc.</span>
</td>
</tr>
</table>
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
17
Microsoft | Services
Slide 189
Slide 190
<configuration>
<system.web>
<pages masterPageFile="~/Site.master" />
</system.web>
</configuration>
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
18
Microsoft | Services
Slide 191
Default Content
Slide 192
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
19
Microsoft | Services
Slide 193
Title of a page
<@Page MasterPageFile=”simple. master” Ti tle=”Hel l o,
master” %>
Nested master pages
Exposing Master Properties
You can change a master page dynamically
PreInit event
this.MasterPageFile
Slide 194
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
20
Microsoft | Services
Slide 195
♦Site Navigation
Introduction
Schema
TreeView
SiteMapDataSource
SiteMapPath
Site Map Providers & API
Slide 196
Site Navigation
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
21
Microsoft | Services
Slide 197
Server Controls
M enu TreeView SiteM apPath SiteM apDataSource
Site Navigation
SiteM apNode SiteM apNode SiteM apNode SiteM ap class
API
Provider Layer
Relational
web.sitemap User Defined
Store
Slide 198
TreeView Controls
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
22
Microsoft | Services
Slide 199
Declaring a TreeView
<asp:TreeView RunAt="server>
<Nodes>
<asp:TreeNode Text="Training" RunAt="server">
<asp:TreeNode Text="Programming .NET" RunAt="server"
Navigateurl="Classes.aspx?id=1" />
<asp:TreeNode Text="Programming ASP.NET" RunAt="server"
NavigateUrl="Classes.aspx?id=2" />
<asp:TreeNode Text="Programming Web Services" RunAt="server"
NavigateUrl="Classes.aspx?id=3" />
</asp:TreeNode>
<asp:TreeNode Text="Consulting" RunAt="server"
NavigateUrl="Consulting.aspx" />
<asp:TreeNode Text="Debugging" RunAt="server"
NavigateUrl="Debugging.aspx" />
</Nodes>
</asp:TreeView>
Slide 200
Name Description
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
23
Microsoft | Services
Slide 201
SiteMapDataSource
Slide 202
<siteMap>
<siteMapNode title="Home" description="" url="default.aspx">
<siteMapNode title="Training" url="Training.aspx"
description="Training for .NET developers">
<siteMapNode title="Programming .NET" url="Classes.aspx?id=1"
description="All about the .NET Framework" />
<siteMapNode title="Programming ASP.NET" url="Classes.aspx?id=2"
description="All about ASP.NET" />
<siteMapNode title="Programming Web Services" url="Classes.aspx?id=3"
description="All about Web services" />
</siteMapNode>
<siteMapNode title="Consulting" url="Consulting.aspx"
description="Consulting for .NET projects" />
<siteMapNode title="Debugging" url="Debugging.aspx"
description="Help when you need it the most" />
</siteMapNode>
</siteMap>
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
24
Microsoft | Services
Slide 203
Web.sitemap
<siteMap>
<siteMapNode title="Home" description="" url="default.aspx">
<siteMapNode title="Training" url="Training.aspx"
description="Training for .NET developers">
<siteMapNode title="Programming .NET" url="Classes.aspx?id=1"
description="All about the .NET Framework" />
<siteMapNode title="Programming ASP.NET" url="Classes.aspx?id=2"
description="All about ASP.NET" />
<siteMapNode title="Programming Web Services" url="Classes.aspx?id=3"
description="All about Web services" />
</siteMapNode>
<siteMapNode title="Consulting" url="Consulting.aspx"
description="Consulting for .NET projects" />
<siteMapNode title="Debugging" url="Debugging.aspx"
description="Help when you need it the most" />
</siteMapNode>
</siteMap>
Slide 204
<configuration>
<system.web>
<siteMap>
<providers>
<remove name="AspNetXmlSiteMapProvider" />
<add name="AspNetXmlSiteMapProvider"
type="System.Web.XmlSiteMapProvider, System.Web, ..."
siteMapFile="Acme.sitemap" />
</providers>
</siteMap>
</system.web>
</configuration>
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
25
Microsoft | Services
Slide 205
<siteMapNode> Attributes
Name Description
Slide 206
Security Trimming
Visible to everyone
<siteMap>
<siteMapNode title="Home" description="" url="default.aspx">
<siteMapNode title="Announcements" url="Announcements.aspx"
description="Information for all employees" roles="*" />
<siteMapNode title="Salaries" url="Salaries.aspx"
description="Salary data" roles="Managers,CEOs" />
<siteMapNode>
</siteMap>
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
26
Microsoft | Services
Slide 207
<configuration>
<system.web>
<siteMap>
<providers>
<remove name="AspNetXmlSiteMapProvider" />
<add name="AspNetXmlSiteMapProvider"
type="System.Web.XmlSiteMapProvider, System.Web, ..."
securityTrimmingEnabled="true"
siteMapFile="web.sitemap" />
</providers>
</siteMap>
</system.web>
</configuration>
Slide 208
SiteMapDataSource Properties
Name Description
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
27
Microsoft | Services
Slide 209
Web.sitemap
< s i teMap>
< s i teMapNode t itle="Home" description="" u rl="default.aspx">
< s i teMapNode t itle="Training" u rl="Training.aspx"
d e scription="Training for . NET d evelopers">
< s iteMapNode t itle="Programming . NET" u rl="Classes.aspx?id=1"
d e scription="All a bout t he . NET F ramework" / >
< s iteMapNode t itle="Programming A SP.NET" url="Classes.aspx?id=2"
d e scription="All a bout A SP.NET" / >
< s iteMapNode t itle="Programming W eb S ervices" u rl="Classes.aspx?id=3"
d e scription="All a bout W eb s ervices" / >
< / s iteMapNode>
< s i teMapNode t itle="Consulting" u rl="Consulting.aspx"
d e scription="Consulting f or . NET p rojects" / >
< s i teMapNode t itle="Debugging" u rl="Debugging.aspx"
d e scription="Help w hen you n eed i t t he m ost" / >
< / s iteMapNode>
< / s iteMap>
Slide 210
SiteMapPath Controls
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
28
Microsoft | Services
Slide 211
Using SiteMapPath
Slide 212
Name Description
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
29
Microsoft | Services
Slide 213
Stylizing SiteMapPath
Slide 214
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
30
Microsoft | Services
Slide 215
Slide 216
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
31
Microsoft | Services
Slide 217
SiteMap.ResolveSiteMap
Slide 218
Lab: Navigation
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
32
Microsoft | Services
Slide 219 – Module 3: Server Controls
Module 3:
Server Controls
Slide 220
Overview
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
33
Microsoft | Services
34
Microsoft | Services
Slide 221
Slide 222
HTML Controls
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
35
Microsoft | Services
Slide 223
HtmlInputControl
HtmlInputButton
BoxHtmlInputFile
HtmlInputImage
HtmlInputHidden
HtmlInputRadioButton
…
HtmlContainerControl
HtmlAnchor
HtmlForm
HtmlSelect
HtmlButton
HtmlTable
…
Slide 224
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
36
Microsoft | Services
Slide 225
Web Controls
Defined in System.Web.UI.WebControls
WebControl is the base class
Use runat=„server”
More abstract in API design and richer in functionality
than HTML controls
On ASPX page, they use ASP namespace prefix
Almost the same markup as HTML controls
Slide 226
Button
CheckBox
FileUpload
HiddenField
HyperLink
Image
Panel
TextBox
Table
Calendar
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
37
Microsoft | Services
Slide 227
Validation controls
Slide 228
Validators (cont.)
BaseValidator class
Properties: ControlToValidate, ErrorMessage, ForeColor,
ValidationGroup
Examples:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
38
Microsoft | Services
Slide 229
Slide 230
User Controls
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
39
Microsoft | Services
Slide 231
An example
Message.ascx
<%@ Control Language=”C#” CodeFile=”Message.ascx.cs”
Inherits=”Message” %>
Message.ascx.cs
public partial class Message : System.Web.UI.UserControl {
public string ForeColor;
public string Text;
}
ASPX file
<%@ Page Language=”C#” CodeFile=”Test.aspx.cs” Inherits=”TestUserCtl ” %>
<%@ Register Src=”Message.ascx” TagName=”Message” TagPrefix=”x” %>
<html><body><form id=”form1” runat=”server”>
<x:Message ID=”Message1” runat=”server” />
</form></body></html>
Slide 232
Lab: Validation
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
40
Microsoft | Services
Slide 233 – Module 4: ADO.NET
Module 4:
ADO.NET
Slide 234
Overview
Introduction
Data Providers
Data Containers
Data Controls
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
41
Microsoft | Services
42
Microsoft | Services
Slide 235
Principal components
Main features
Type of providers
Main classes:
SqlConnection
SqlCommand
SqlDataReader
Connection String
Slide 236
Principal components
Connection
Transaction
Command
Parameter
DataAdapter
CommandBuilder
DataReader
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
43
Microsoft | Services
Slide 237
Main features
Disconnected data
Connected data access
Slide 238
Types of providers
Types of providers
Managed Providers
•System.Data.SqlClient
•Microsoft.SqlServerCe.Client
OLE DB Providers
ODBC drivers (System.Data.Odbc)
Oracle (System.Data.OracleClient)
…
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
44
Microsoft | Services
Slide 239
SqlConnection
Slide 240
Connection String
Should be protected
Connection Pooling is enabled by default
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
45
Microsoft | Services
Slide 241
SqlCommand
Properties:
CommandText, CommandTimeout, CommandType, Connection,
Transaction, etc.
Methods:
ExecuteNonQuery, ExecuteReader, ExecuteScalar, Cancel,
CreateParameter, etc.
Synchronously or asynchronously
An example:
using (SqlConnection conn = new SqlConnection(ConnStri ng)){
SqlCommand cmd = new SqlCommand(sprocName, conn);
cmd.CommandType = commandType.StoredProcedure;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}
Slide 242
SqlDataReader
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
46
Microsoft | Services
Slide 243
SqlDataReader: an example
An example:
using (SqlConnection conn = new SqlConnection(connString) ) {
string cmdText = “SELECT * FROM customers”;
SqlCommand cmd = new SqlCommand(cmdText, conn);
cmd.Connection.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
CustomerList.Items.Add(reader[“companyname”].ToStri ng());
reader.Close();
}
Slide 244
Data Adapters
Data Sets
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
47
Microsoft | Services
Slide 245
Data Adapters
Slide 246
SqlDataAdapter
Properties:
DeleteCommand, SelectCommand, UpdateCommand
AcceptChangesDuringFill, AcceptChangesDuringUpdate,
TableMappings
Methods:
Fill, Update, GetFillParameters
An example:
DataSet ds = new DataSet() ;
adapter.Fill(ds);
Adapter.Fill (ds, “MyTable”);
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
48
Microsoft | Services
Slide 247
DataSet
Slide 248
adapter.Update(ds, „MyTable”);
Executes Insert, Update, Delete statement for each
modified row
ContinueUpdateOnError
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
49
Microsoft | Services
Slide 249
Command Builder
Slide 250
Useful containers
In System.Data namespace:
DataSet
DataTable
DataRow
DataColumn
DataView
DataRelation
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
50
Microsoft | Services
Slide 251
Data Controls
Binding Model
Data-bound controls
Data source components
Slide 252
Binding model
Data-bound controls:
List and iterative controls
Implements DataBoundControl class
Data-Binding Properties:
DataSource, DataSourceID
DataMember
DataTextField, DataTextFormatString, DataValueField
DataKeyField
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
51
Microsoft | Services
Slide 253
List Controls:
DropDownList
CheckBoxList
RadioButtonList
ListBox
BulletedList
Iterative Controls
Repeater
DataList
DataGrid
Slide 254
SqlDataSource
ObjectDataSource
GridView
DetailsView
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
52
Microsoft | Services
Slide 255
Module 5:
LINQ
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
53
Microsoft | Services
Slide 257
Overview
Introduction
Examples
LINQ to XML
LINQ to SQL
LINQ to DataSet
Slide 258
LINQ: Introduction
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
54
Microsoft | Services
Slide 259
Some examples:
Query expression:
var contacts =
from c in customers
where c.City == “Warszawa"
select new { c.Name, c.Address };
Lambda expression:
var contacts =
customers
.Where(c => c.City == “Warszawa")
.Select(c => new { c.Name, c.Address });
Slide 260
LINQ to XML
Creating XML
Constructors lend themselves to nesting
Can use LINQ (over anything) to build XML
Querying
Use normal axes from XML infoset
Get full power of query expressions over XML
Select, where, group by, etc.
Xml Namespaces
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
55
Microsoft | Services
Slide 261
LINQ to SQL
Slide 262
LINQ to SQL
DML or Stored
SQL Rows Procedures
Query
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
56
Microsoft | Services
Slide 263
LINQ to DataSet
Slide 264
Lab: LINQ
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
57
Microsoft | Services
Slide 265 – Module 6: ASP.NET AJAX
Module 6:
ASP.NET AJAX
Slide 266
Overview
Introduction
Visual Studio 2008 AJAX Support
Developer scenarious
Update Panel
ASP.NET AJAX Control Toolkit
Control Extenders
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
58
Microsoft | Services
59
Microsoft | Services
Slide 267
Introduction
Slide 268
Introduction (cont.)
XMLHttpRequest
Sends HTTP request synchronously or asynchronously
Microsoft AJAX JavaScript library
ASP.NET AJAX assembly: system.web.extensions
JavaScript files are resource files in the assembly
Defines:
Core framework clases (Sys.WebForms, Sys.Net, Sys.Services,
Sys.Serialization, Sys)
User-interface framework classes (Sys.UI)
Script Manager and Script Manager Proxy controls
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
60
Microsoft | Services
Slide 269
JavaScript Intellisense
Code intellisense for client-side JavaScript
Integrated editor support for ASP.NET AJAX JS Library
Intellisense against JSON enabled .asmx web services
JavaScript Debugging
Improved discoverability
Slide 270
Postback
protected void Handler()
{}
Updated Rendering
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
61
Microsoft | Services
Slide 271
Updated Rendering
(only region in protected void Handler()
{}
UpdatePanel)
Supporting Scripts
Slide 272
UpdatePanel control
<asp:UpdatePanel> control
Easily define “updatable” regions of a page
Server roundtrips become asynchronous
ASP.NET AJAX handles all the infrastructure
Supports Triggers that allow other controls to fire the
Postback
<asp:UpdatePanel id=“updatepanel1” runat=“server”>
<ContentTemplate>
<ContentTemplate>
</asp:UpdatePanel>
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
62
Microsoft | Services
Slide 273
Showing Progress
<asp:UpdateProgress ID="UpdateProgress1“
runat="server">
<ProgressTemplate>
Please Wait ...
</ProgressTemplate>
</asp:UpdateProgress>
Slide 274
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
63
Microsoft | Services
Slide 275
Control Extenders
Slide 276
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
64
Microsoft | Services
Slide 277 – Module 7: Additional Topics
Module 7:
Additional Topics
Slide 278
Overview
Error Handling
State Management
Security
Membership and Role Managers
Performance Best Practices
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
65
Microsoft | Services
66
Microsoft | Services
Slide 279
♦Error handling
Slide 280
Best Practices
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
67
Microsoft | Services
Slide 281
♦State Management
Introduction
Application
Session state
View State
Caching
Slide 282
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
68
Microsoft | Services
Slide 283
Application
Application.Lock();
int val = (int) Application[“MyValue”];
if (val < 10)
Application[“MyValue”] = val + 1;
Application.UnLock();
Slide 284
Session State
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
69
Microsoft | Services
Slide 285
Slide 286
View State
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
70
Microsoft | Services
Slide 287
Caching
Cache class
Can be confgured to expire after a specifed number of
seconds
Globally visible class which works in current Application
Domain
Don’t work in web garden or web farm scenario
Cache[“MyData”] = value;
Slide 288
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
71
Microsoft | Services
Slide 289
♦Security
ASP.NET Processing
Authentication vs. Authorization
Authentication methods
IIS Authentication and Authorization Process
ASP.NET web site configuration
Application pool account and permissions
IIS Built-in accounts
Code Access Security
Global Assembly Cache
Attack Methods
Best Practices
Slide 290
ASP.NET Processing
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
72
Microsoft | Services
Slide 291
Slide 292
1. Is IP address permitted?
2. Is user permitted?
Valid credentials
Account restrictions
Time, Lockout, Password expired, Privileges
3. Does IIS allow access?
4. Does NTFS allow access?
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
73
Microsoft | Services
Slide 293
Authentication methods
Passport
Anonymous
Certificates
Authentication is defined in web.config file
Forms
Windows
Passport
Slide 294
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
74
Microsoft | Services
Slide 295
Slide 296
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
75
Microsoft | Services
Slide 297
Slide 298
Account Description
A built-inaccount that has a high level of access rights
LocalSystem Avoid assigning LocalSystem as an application pool
identity
A built-in
IIS account with low privileges
Interacts
throughout the network with the computer
Network Service account
The default application pool identity (recommended)
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
76
Microsoft | Services
Slide 299
Slide 300
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
77
Microsoft | Services
Slide 301
Slide 302
Attack methods
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
78
Microsoft | Services
Slide 303
Slide 304
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
79
Microsoft | Services
Slide 305
Slide 306
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
80
Microsoft | Services
Slide 307
Membership service
Login controls
Role Management service
FBA: Best Practices
Slide 308
♦Membership Service
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
81
Microsoft | Services
Slide 309
Membership Schema
Controls
Other Login
Login LoginStatus LoginView Controls
Membership API
Membership MembershipUser
Membership Providers
Membership
Data
Other
SQL Server AD/AzMan
Data Stores
Slide 310
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
82
Microsoft | Services
Slide 311
Name Description
Slide 312
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
83
Microsoft | Services
Slide 313
Name Description
Slide 314
Membership Providers
Membership is provider-based
Provider provides interface between membership
service and physical data store
ASP.NET ships with one provider
SqlMembershipProvider (SQL Server or SQL Server
Express)
Use custom providers for other data stores
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
84
Microsoft | Services
Slide 315
Provider Configuration
Slide 316
<membership>
<providers>
<remove name="AspNetSqlProvider" />
<add name="AspNetSqlProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, ..."
connectionStringName="RemoteSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
description="Stores and retrieves membership data ..."
/>
</providers>
</membership>
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
85
Microsoft | Services
Slide 317
Login Controls
Control Description
Slide 318
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
86
Microsoft | Services
Slide 319
Slide 320
Controls
Other Login
Login LoginStatus LoginView Controls
Roles API
Roles
Role Providers
Roles Data
Other
SQL Server AuthMan
Data Stores
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
87
Microsoft | Services
Slide 321
Slide 322
Name Description
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
88
Microsoft | Services
Slide 323
Slide 324
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
89
Microsoft | Services
Slide 325
Slide 326
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
90
Microsoft | Services
Slide 327
Slide 328
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
91
Microsoft | Services
Slide 329
WebApplication
Page1.
aspx
Page2.
aspx Batch Compilation WebApplication.dll
Page3.
aspx
Slide 330
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
92
Microsoft | Services
Slide 331
Slide 332
String
String Concatenation
String Concatenation Is Bad
String Concatenation Is
Final String
Temporary Strings
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
93
Microsoft | Services
Slide 333
Slide 334
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
94
Microsoft | Services
Slide 335
Slide 336
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
95
Microsoft | Services
Slide 337
HTTP Modules
96
Microsoft | Services