Index [link.springer.com]978-1-4302-4255...NuGet dependency management, 112, 114 jQuery.Validation package, 113 Microsoft jQuery Unobtrusive Validation package, 112–113 package installation,
Post on 23-Mar-2021
13 Views
Preview:
Transcript
A���������AcquireRequestState event, 321–322, 372AddAttribute method, 862AddButtonClickHandlers method, 803addClass function, 90AddError method, 342Admin.Master page, 309Ajax
categoryFilter, 1121event validation
disable event validation, 1119DropDownList control, 1118EventValidationDemo.aspx file, 1118replacement, 1121span element, 1118trigger, 1119
ModelBinding.aspx, 1123productController.cs file, 1122product repository class, 1101UpdatePanel, 1099web services
application data, 1115Data.aspx Web Form, 1112deleteData function, 1115Get method, 1109goals, 1102HTTP method, 1102JSON, 1101JSON formatter, 1109Json.Net package, 1110/Models/Product.cs file, 1109model validation errors, 1117ProductController class, 1108ProductController.cs file, 1111ProductID property, 1113ProductView class, 1111REST, 1101routing configuration, 1104
script/data.js file, 1115testing, 1107updateData function, 1115Web API feature, 1103
AjaxSourceModule.cs, 442–443AllowPaging attribute, 1024, 1027AlternatingItemTemplate, 1013AppendDataBoundItems attribute, 994, 1000, 1002Application_BeginRequest method, 325Application_End method, 317, 324Application_End(src, args), 317applicationhost.config file, 395Application lifecycle
Application_End method, 317, 319–320Application_End(src, args), 317Application_Start method, 317–320Application_Start(src, args), 317Default.aspx Web Form, 319initialization, 318
Application settingsvs. application state, 729code-behind method, 730defining, 728displaying, 729overriding, 730
Application_Start method, 317–318, 324, 609Application_Start(src, args), 317App_Start/BundleConfig.cs file, 1021asp:Content control, 141ASP.NET 4.5, 31ASP.NET application
data creationClass template, 9CodeBehind attribute, 13code-behind class, 14CSS styles, 12data model, 9Default.aspx file, 13form creation, 11
Index
1165
form element, 12GuestReponse class, 10HTML elements, 16–18HTML response files, 16key features, 9link element, 12–13Page_Load method, 15Response.Redirect method, 15ResponseRepository class, 10style elements, 12TryUpdateModel method, 15
multiple browsers, 7project creation
ASP.NET Empty Web Application, 4browser window, 7HTML, 8–9IIS Express, 8Internet Explorer, 7key points, 9left-hand panel, 4new Web Form, 5–6Solution Explorer window, 4–5URL, 8Visual Studio toolbar, 6–7Web Form, 5
summary view creationcode-behind method, 21–23dynamic code, 20–21dynamic HTML, 20HTML strings, 20Summary.aspx file, 18–19<% and %> tags, 19
validation techniquecustom validation message, 27GuestResponse class, 23–24problems, 24–26Required attribute, 24WillAttend select element, 26
workstation, 3ASP.NET bundling feature. See Script
and style managementASP.NET development tools
EssentialTools projectapplication testing, 103Default.aspx.cs file contents, 102Default.aspx file contents, 101Styles.css file contents, 102Visual Studio debugger
(see Visual Studio debugger)F12 tools
F12 key, 108Internet Explorer 10, 108JavaScript Console, 108JavaScript profiler, 111network monitor, 110
JavaScript libraries, 115NuGet
dependency management, 112, 114jQuery.Validation package, 113Microsoft jQuery Unobtrusive
Validation package, 112–113package installation, 114
Opera Mobile, 114Page Inspector
advantage, 108Inspect, HTML, and Files buttons, 108Internet Explorer 10, 108layout, 107–108
ASP.NET Empty Web Application template, 4, 281, 313, 369, 1051
ASP.NET framework, 371C# language features, 31code-behind file, 30code nuggets, 30controls, 30Definitive Guide to HTML5, 32evolution and restructuring of, 30hybrid platform, 32IIS, 32jQuery, 31lifecycles (see Lifecycles).NET UI toolkit, 30structure of, 29
client-side development, 33core ASP.NET platform, 33core language features and tool, 33forms and controls, 33SportsStore, 32
Visual Basic programming model, 29web application, 31web development tool, 29Web Forms (see Web Forms)
ASP.NET State Service, 472ASP.NET Web Forms Application template, 119Asynchronous methods
async and await keywords, 72GetPageLength, 70MyAsyncMethods, 70System.Net.Http assembly, 70task continuation, 71
Asynchronous Module Definition (AMD) standard, 116
Asynchronous request handlingcondition for applying, 764connection thread pool, 763exhausted the thread pool, 764handlers
contents of AsyncHandler.cs class file, 774
generating response, 775registering, 774
■ index
1166
ASP.NET application (cont.)
modulescontents of AsyncModule.cs file, 772displaying, 773registering, 772
parallel programming, 761project preparation, 761time taken for, 764WebClient.DownloadString method, 764Web Form
creating and registering page task, 767declaring, 765DownloadStringTaskAsync method, 767effect of asynchronous request processing, 766implementing, 765IO completion ports, 767multiple tasks, 768Task Parallel Library, 767
async keyword, 72AsyncMode property, 420Attribute selectors, 85AuthenticateRequest event, 321Authentication
ASP.NET configuration, 670forms authentication, 669master page
/Admin/Open.aspx Web Form, 695Auth.Master file, 692–693div element, 693postback vs. non-postback requests, 694
MultiFactor, 670performance
Account folder, 672–673/Account/Login.aspx Web Form, 677AuthTest.aspx Web Form, 674benefit, 674HttpContext.User object, 676IIdentity interface, 677input elements, 675IPrinciple interface, 676Log In button, 675methods and properties, 675–676Response.Redirect method, 676SignOut method, 676Web Form, 673
project preparation, 667rebuilding, 691testing, 695
Authorizationbypassing
/Admin/Open.aspx file, 689AuthModule.cs class file, 686–687high-risk technique, 687location element, 688SkipAuthorization property, 687Web.config file, 688
integrationcookie, 678deny element, 678grant access, 679location-specific policy, 684location-specific Web.config file, 686loginUrl attribute, 678Page_Load method, 679policy creation, 683restrict access, 679role provider, 680testing authentication redirection, 679Web.config file, 678
testing, 695URLs routing, 689
AuthorizeRequest, 321AutoEventWireup attribute, 409–410await keyword, 72Azure portal, 233
B���������BaseContainer class, 58Basic data controls
avoided and used, 992Controls/ListSelect.cs file, 1016DataSelect control, 1017example project
adding jQuery, 992Data project, 992Styles.css file contents, 992
listBulletedList control (see BulletedList control)CheckBoxList control (see CheckBoxList control)DropDownList control
(see DropDownList control)HTML elements, 993ListBox control (see ListBox control)ListControl class, 993RadioButtonList control
(see RadioButtonList control)UI model, 1006
ListItemDetails class, 1017ListItem objects, 1015, 1019ListSelectDemo.aspx.cs file, 1018ListSelectDemo.aspx file, 1017problems and solutions, 991Product objects, 1018Repeater control (see Repeater control)
BeginRequest event, 443BeginRequest method, 341bind function, 95–96BlockingCollection class, 387Bookmarklet, 108Breakable/composable style, 145
■ index
1167
Browser F12 toolsF12 key, 108Internet Explorer 10, 108JavaScript Console, 108JavaScript profiler, 111network monitor, 110
BuildManager.CreateInstanceFromVirtualPath method, 405
BulletStyle attribute, 1009BundleConfig.RegisterBundles method, 1079Bundles, 197ButtonClick method, 797–798, 827:button filter, 95
C���������CacheDependency, 497CachedForm.aspx.cs code-behind file, 516CachedForm.aspx file, 515CacheItemUpdateReason enumeration, 509Cache.Remove method, 509Caching
application cache, 490–491ASP.NET Empty Web Application, 487cached data, 492CitiesControl.ascx.cs code-behind file, 487–488CitiesList.html file, 488configuration, 509, 511CurrentTime.ascx, 487Default.aspx.cs code-behind file, 489, 513Default.aspx file, 489Default.aspx Web Form, 490dependencies
aggregate dependencies, 500CitiesControl.ascx.cs
code-behind file, 493CityListInfo, 494custom dependency, 497–500external dependency, 496HTML file, 495internal dependency, 496–497System.Web.Caching.CacheDependency, 495
expiration constraints, 501–502GetCities method, 488MapPath method, 488receiving notification
cache ejection, 505–506perform eager cache updates, 506–507prevent ejection, 507–509
scavenging prioritization, 502–504STCacheObject.cs file, 511Web User Control item template, 487
Caching outputaddition, 525application, 515
cache implementationcreation, 535dynamic selection, 538registration, 537
characteristics, 518configuration, 540dependency, 533dynamic content, 527handler factory (see Handler factory)server control, 531substitution control, 525, 527substitution method, 526user control
attribute definition, 529nested control, 530SharedControl.aspx file, 529timestamp, 528–529UnCachedForm.aspx file, 527–528
Web Formasterisk value, 520attribute definition, 518authentication code, 520cached data, 520cache profile, 523end-to-end caching, 519GetVaryByCustomString method, 522–523quantity and price input element, 520VaryByCustom attribute, 522VaryByHeader attribute, 521VaryByParam attribute, 521
CartSummary control, 179Cascading Style Sheets (CSS), 12Category
add CSS styles, 153apply user control to master page, 152display, 155expand URL scheme, 153highlighting current category, 157user control creation, 150
CdnInclude method, 1096CheckBoxList control
Check.aspx.cs code-behind file, 995Check.aspx file, 994element layout
adding extra columns, 998attributes, 997data items display, 997data values display, 996RepeatColumns attribute, 997RepeatLayout attribute, 997table element, 997
elements in client scripts, 1000GetProducts method, 994handling control events, 999handling selections, 998
■ index
1168
input elements, 994–995label elements, 994–995ListControl class, 994ListItem control, 994ToString method, 995
Checkout link, 185CheckoutUrl property, 186CheckZip method, 939–940CitiesControl.ascx.cs code-behind file, 500CitiesControl.ascx.cs file, 500C# language features
anonymous types, 54async methods (see Asynchronous methods)automatic type inference, 53explicit interface implementation
GetCurrent method, 62–63IMonthProvider interface, 62IYearProvider interface, 62MyInterfaces.cs file, 62TimeProvider class, 63–64
extension methods (see Extension methods)generic typing
common base class, 58DateTimeContainer class, 56–57MyContainers.cs file, 56parameter, 60–61rewriting initial code, 61StringContainer class, 56–57ValueContainer class, 60
initializerscollections and arrays, 43object, 42
lambda expressions (see Lambda expressions)LINQ (see Language Integrated Queries (LINQ))project creation, 37properties
automatic, 40consumption, 39defining, 38GetMessage method, 39Name, 39regular, 41verbose, 40
ClientScriptManager class, 1093Client-side validation, 195
App_Start/BundleConfig.cs file, 1129built-in validation control
CreateProduct.aspx file, 1134duplicated errors, 1136model binding feature, 1137RangeValidator, 1135RequiredFieldValidator, 1135ValidationSummary control, 1135–1136
CreateProduct.aspx file, 1127CreateProducts.aspx.cs file, 1127
data attributes, 199–200data-valmsg-summary attribute, 200data-val-required attribute, 200HTML5
checkValidity function, 1132CreateProduct.aspx file, 1131feature implementation, 1133input element, 1132price element, 1131required attribute, 1131script element, 1132setCustomValidity function, 1132
.input-validation-error class, 1139JavaScript code, 1147–1148JavaScript library, 1129jquery.validate.unobtrusive.js file, 1137jQuery.validation library, 1139message, 200–201model binding, 1146models/product.cs file, 1125Name property, 1137Page_Load method, 1128product object, 1128propertyTemplate, 1144unobtrusive validation library, 1140ValidationRepeater control, 1144web service updation, 1145
Code-behind class, 14Code nuggets
content, 285, 287data binding, 287–289property, 290–291standard, 284types of, 283
CommandArgument attribute, 1027, 1045CommandName attribute, 1027, 1034, 1043, 1045CommonPageBase.cs, 296CompleteRequest method, 334, 343Complex data controls
example projectextending CSS, 1022script management, 1021
FormView control (see FormView control)ListView control (see ListView control)
CompositeDataBoundControl, 975, 1059Conditional breakpoints, 104Configuration
application settingsoverriding, 730working with, 728
complete configuration, 740configuration sections (see Configuration sections)connection strings
database connection using, 735working with, 732
■ index
1169
hierarchy, 726project preparation, 725using external configuration files, 754WebConfigurationManager class, 728
Configuration sectionsappSettings and connectionStrings elements, 736collection configuration section
collection of values, 748enumerating, 751PlaceCollection.cs file, 749Place.cs file, 748PlaceSection.cs file, 750
custom configuration section, 747, 759defining, 746, 750group, 752HttpContext.GetSection method, 738locking
applying, 756breaking a lock, 757locking attributes, 756requesting locked configuration sections, 757revising the locks, 758
section handler classcall-back method for custom validation, 745ConfigurationProperty attribute, 744create, 744
setting values for, 743single section
display section values, 738GetWebApplicationSection method, 737section handler class, 739
system.Web element, 736Connection strings
adding, 732database connection
adding application setting, 735getting connection string and
querying database, 735enumerating, 734properties defined, 734reading, 733removing, 735
Connection thread pool, 763Constraints
HTTP methodsaction and method attribute, 641a element, 641/App_Start/RouteConfig.cs file, 641custom route restriction, 642definition, 642GET and POST, 640GetTest.aspx Web Form, 640/methodtest URL, 641–642PostTest.aspx file, 641
Content code nuggets, 284–287Content control, 170Content Delivery Network (CDN), 1085Content filters, 88ContentLength header, 71ContentPlaceHolder control, 141, 304ContentType property, 374Context.ApplicationInstance property, 419Context class, 184Context objects
HttpApplication (see HttpApplication object)HttpContext objects, 330–331HttpRequest objects, 335–337HttpResponse objects, 337, 339
ContinueWith method, 72ControlCollection class, 806Control hierarchy
Add method, 806Colors.aspx file, 805ControlCollection class, 806dynamical Button controls, 807FindControl method, 806HTML elements, 799key element, 805location and manipulation
Button control, 803event-handler method, 802label duplication problem, 804
navigationControl class, 799ControlUtils class, 800ControlUtils.cs file, 799–800EnumerateControls method, 801HTML elements, 802LiteralControl class, 800Output, 800Page_Load method, 800
ControlsASP.NET project, 780base control class, 781custom controls
ASCX file, 784ButtonCountUserControl.ascx, 783buttons, 786code-behind class, 784form element, 788HTML fragment, 784nesting, 786properties, 784register, 785state and request handling, 787Web Forms, 783
data controlsButtonCountResult class, 793buttons, 795
■ index
1170
Configuration (cont.)
data-related attributes, 793definition, 792Index and Count properties, 793register, 794Repeater controls, 792TripleButtonControl.ascx file, 792view model, 793
hierarchy (see Control hierarchy)HTML element, 782Page class, 780project preparation, 779Repeater control, 808rich UI controls
abstractions, 797ButtonClick method, 797–798characteristic, 797HTML fragment, 796implementation, 795Label and Button, 796WebControl class, 798
server controlsButtonCounterServerControl.cs file, 788Default.aspx file, 790–791HtmlTextWriter methods, 790Register directive, 791RenderContents method, 789WebControl class, 789
user and server controls, 788Control state
broken Calc control, 891CalcState class, 899Custom/Calc.ascx.cs File, 898Custom/Counter.ascx.cs File, 877dead control state, 870effect of, 879effect of control buttons, 869GetSessionKey method, 872GetValue method, 873input elements, 872–873LeftValue and RightValue properties, 868LoadControlState method, 879LoadStateData method, 872–873project preparation, 867RegisterRequiresControlState method, 878–879registers, user control, 868SaveControlState method, 879SaveStateData method, 872state collisions, 871view state, 874
button element, 891Calc control, 894, 898configuration, 886Counter control, 877Custom/Counter.ascx.cs file, 874Custom/Counter.ascx file, 874Custom/SimpleTime.cs file, 879
DataBind method, 894–896disabling, 884, 886–887, 898duplication, 895enabling, 887–888Event-Handler Code, 892history, 896HistoryCalc.aspx File, 898Inherit value, 886input elements, 874, 891, 893Repeater control, 894–897SelectMethod, 894SimpleState.aspx.cs file, 881SimpleState.aspx file, 880SimpleState.aspx Web Form, 883, 885SimpleTime control, 881system.web.pages element, 882Take method, 897testing, 882ViewStateMode, 885–888, 896Web.config file, 868, 884–885Web Forms, 886
zombie control state, 870ControlUtils class, 800ControlValueProvider class, 952Counter.ascx.cs file, 871CounterControlState, 875CreateChildControls method, 1059Cross-Site Scripting, 829CS file extension, 282csLink variables, 178csQuantity variables, 178CssClass attribute, 1028csTotal variables, 178CurrentDayHandler, 385CurrentExecutionFilePathExtension
property, 379CurrentNotification property, 328–329CurrentPage property, 132, 135CurrentTimeHandler.asxh file, 426, 541CurrentTimeHandler class, 434CurrentTimeHandler instance, 385Custom.Calc.ascx.cs file, 889Custom/Calc.ascx.cs file, 892–893, 897Custom/Calc.ascx file, 888–889, 892, 896CustomChecks class, 939Custom controls
ASCX file, 784ButtonCountUserControl.ascx file, 783buttons, 786code-behind class, 784creation
BasicCalc.ascx File, 841Control directive, 841file extension, 841registering (see Registering controls)user control, 841
■ index
1171
element attributesBasicCalc control, 850code-behind properties, 851collection, 854configuration, 852enumeration attribute, 852feature, 852simple attributes, 852value attributes, 851
form element, 788functionality
calculator, 847code-behind class, 846Control class, 847control features, 845GetId method, 846HTML elements, 845name attribute, 847
HTML fragment, 784identification
control hierarchy, 849HTML elements, 848
jQuery, 840nesting, 786project preparation, 839properties, 785register, 785server controls (see Server controls)state and request handling, 787Web Forms, 783
Custom/Counter.ascx.cs file, 867, 872Custom/Counter.ascx file, 867Custom handler
contents, 379CustomHandler.cs, 379IHttpHandler interface, 379registering, 379–380
CustomHandler class, 660CustomHandler.cs, 379Custom handler factory
controlling handler instantiation, 382–383GetHandler method, 381IHttpHandlerFactory, 381parameters, 381recycling handlers, 385–387registering, 397selection control, 384–385test, 398–399
Custom/SimpleTime.cs file, 879
D���������Data.aspx class, 953Data binding, 162–163
configurationdata-binding code nuggets, 967data item type, 966data manipulation, 968–969GetCategories method, 968GetProductData method, 967HtmlSelect control, 970ItemType attribute, 967Person model class, 968public data method, 967SelectMethod attribute, 967
control declaration, 987custom data control
adding template, 978, 980CompositeDataBoundControl, 975DataBoundControl, 974DataSelect control, 975–976, 983DataSelect.cs file, 973–974Default.aspx.cs code-behind file, 983Default.aspx file, 984ElementItem class, 981–982features, template, 984–986IDataItemContainer interface, 980–981item keyword, 980ItemTemplate element, 983PerformDataBinding method, 974–975RenderContents method, 975table elements generation, 989template property, 981–982view state support, 977–978
DataTable control declaration, 986–987DataTable.cs file, 988–989definition, 961DropDownList control, 972–973example project
Default.aspx.cs code, 964Default.aspx file, 963–964Default.aspx Web Form, 964–965Distinct method, 964GetCategories method, 964GetProductData method, 964Models/Repository/
Repository.cs file, 962–963OrderBy method, 964Product class, 961Product.cs file, 961Repeater control, 964Repository class, 963Serializable attribute, 962static constructor, 963
view model, 970–971Data binding code nuggets, 287–289DataBinding event, 1015DataBind method, 895Data controls
■ index
1172
Custom controls (cont.)
ButtonCountResult class, 793buttons, 795data-related attributes, 793definition, 792Index and Count properties, 793register, 794Repeater controls, 792TripleButtonControl.ascx file, 792view model, 793
DataKeyNames attribute, 1033Data model class, 183dataObject.Name property, 105, 107DataPager control, 1047DataSelect control, 975–976, 983, 1017data-val-required attribute, 200DateTimeContainer class, 57Dead control state, 870Debugger.Break method, 105Declarative event handler, 325Default.aspx.cs code-behind file, 38, 294, 403, 489, 501Default.aspx.cs file, 282Default.aspx file, 6, 37, 281, 425, 869, 877Default.aspx Web Form, 281, 369, 406, 488, 490DeleteProduct method, 1032, 1037DESIGNER.CS file extension, 282DisplayPerson method, 933Document Object Model (DOM), 75
API, 75, 81–82HTML, 83manipulation functions, 92manipulation libraries, 80navigation functions, 91waiting, 80
Donut caching, 526DropDownList control, 993, 1005
Drop.aspx.cs file, 1002Drop.aspx file, 1001ListItem controls, 1002option elements, 1001, 1003SelectedValue and InnerText properties, 1002–1003select element, 1001–1002
E���������EnableEventValidation property, 420EnableViewState attribute, 177, 877EnableViewStateMac property, 420Encoded content code nugget, 286EndRequest method, 341End-to-end web lifecycle, 418–419Error handling
code-behind class, 551customization
ASP.NET HTTP status code, 560custom error page, 556customErrors element, 555–556
dynamic error page, 558, 564Failure.html file, 555HTML Page item template, 555HTTP errors, 559IIS HTTP status code, 561Web.config file, 555Web Form, 566
Default.aspx Web Form, 550–552Error event, 568failure
ASP.NET, 552assumptions, 553definition, 552external resource, 553HTML string, 553System.FormatException, 554users, 554YSOD, 554
handling multiple errorsASP.NET Framework, 573display, 575ErrorModule.cs, 578event handler code, 578HttpContext class, 574intercepting, 576report, 574
PlaceHolder control, 549process
application-level implementation, 570
ComponentError.aspx, 568Default.aspx.cs code-behind file, 568Error event, 569exception, 569HttpApplication class, 570HttpContext.Error property, 569precedence path, 570redirection, 572Web Form, 567
redirectMode attribute, 556RemoteOnly value, 556remote request, 557runat attribute, 550SumControl.acsx file, 549SumControl.ascx.cs file, 550
EventCollection.Add method, 402EventCollection class, 401EventCollection.cs, 313Event-handler method, 892EventSource enumeration, 402Events project, 401Extension methods
applying, 45to interface, 46key statement, 45TotalPrices method, 46
■ index
1173
defining, 44delegate, 50filtering, 48, 50ShoppingCart class, 44
F���������FieldValidator control, 958FilterByCategory method, 49Filtering extension method, 48, 50FindControl method, 806FinishInit method, 499FlexibleRouteHandler class, 662FooterTemplate, 1013FormDataConstraint class, 644Form filters, 89Forms
form dataaspects of, 821checkbox, 824FormData.aspx, 823FormKeyValuePair class, 823GetFormData method, 823name values, 824
jQuery, 814limitation
ButtonClick method, 826HtmlForm control, 825input elements, 826Load event handler, 827MultiForm.aspx File, 825server-side div element, 826Value attribute, 827view state feature, 825
post backsbutton element, 819GET request, 819HTML form, 819HTTP method, 818IsPostBack property, 819Page.IsPostBack property, 818POST requests, 820query string, 819view model class, 822
project preparation, 813server-side element
Default.aspx file, 814DefaultButton and DefaultFocus properties, 816HtmlControls class, 815JavaScript, 817jQuery code, 817jQuery focus method, 817method attribute, 815runat attribute, 824TextBox controls, 816
FormsAuthentication.RedirectFromLoginPage method, 679FormsAuthentication.SignOut() method, 694FormValueProvider class, 937, 952FormView.aspx.cs file, 1024FormView control
attributes, 1024code-behind class, 1024CssClass property, 1024data editing
adding functionality, 1029BindItem.Name, 1035CommandName attribute, 1035creating new record, 1031–1032data method specification, 1032DeleteProduct method, 1032EditItemTemplate, 1034–1035FormView.aspx.cs code-behind file, 1029InsertItemTemplate, 1034InsertProduct method, 1032ItemTemplate, 1035mode management, 1036Name, Category, and Price properties, 1031switching modes, 1033UpdateProduct method, 1031Visible attribute, 1036
data method implementationcode-behind class, 1036deleting data object, 1038model binding, 1037UpdateProduct and DeleteProduct methods, 1037
data modes, 1029events, 1039FormView.aspx file, 1023outer element, 1028templates, 1026
data objects display, 1026ItemTemplate, 1026–1027PagerTemplate, 1027properties, 1028
FormViewMode enumeration, 1033formViewTable class, 1024Fragment caching, 529Friendly URL, 590
disable handlers and modules, 596friendlyUrls library
model binding to path info, 600using extension method, 598
NuGet package installation and configuration, 597
G���������Generic handler
ASP.NET Framework, 375ContentType property, 374HttpContext object, 374implementing custom behavior, 375–376
■ index
1174
Extension methods (cont.)
ProcessRequest method, 374targeting, 375test, 377Time.asxh, 374View Markup, 374WebHandler directive, 374Write method, 374
Generic typingcommon base class, 58DateTimeContainer class, 56–57MyContainers.cs file, 56parameter, 60–61rewriting initial code, 61StringContainer class, 56–57ValueContainer class, 60
GetCart method, 166GetCategories method, 1018GetCities method, 500GetCity code-behind method, 285GetCurrent method, 62, 64GetData method, 951–954GetDayOfWeek method, 297GetFormData method, 823GetFormValue method, 847GetHandler method, 381, 383GetHistory method, 890GetModelValidationErrors method, 942–943GetOutputCacheProviderName method, 538GetPageLength method, 70GetPerson method, 933–934, 942GetProducts method, 994, 1024GetRouteMatches method, 634GetRouteUrl method, 631GetSessionKey method, 872Get<T> method, 166GetValues method, 627, 873GetVaryByCustomString method, 522–523GetVirtualPath method, 168Global application class, 315–316
code-behind class file, 120contents of, 121creation, 119
Global.asax.cs code, 370Global.asax.cs file, 340, 401–402, 1022Global.asax file, 315GuestReponse class, 10
H���������Hackable URLs
/App_Start/RouteConfig.cs file, 621Calc.aspx.cs file, 622Calc.aspx file, 618–619Calc.aspx Web Form, 619code-behind file, 619–620input and select elements, 619
Match, 621query string, 623RouteData.Values property, 622URL format, 621
HandleButtonClick method, 890HandleEvent method, 393, 417Handler factory
creation, 542ASP.NET framework, 546GetHandler method, 544HttpServerUtility.Execute method, 545PageWrapper.cs class file, 546ProcessRequest method, 545static property, 543
CurrentTimeHandler.ashx file, 541registration, 546
Handlersapplicationhost.config file, 395ASP.NET Empty Web Application template, 369ASP.NET Framework, 371classic mode, 395custom (see Custom handler)custom handler factory (see Custom handler factory)Default.aspx, 369generic (see Generic handler)global application class code-behind file, 370Global.asax.cs code, 370HttpContext object, 371HttpRequest.MapPath method, 396HttpRequest object, 371IHttpHandler interface, 371integrated mode, 395modules, 371modules coordination
declarative interfaces, 392–393HttpContext.Items collection, 391HttpContext.Items property, 390Items collection, 391Items property, 389PostRequestHandlerExecute event, 390Time.ashx, 391TotalDurationModule.cs file, 389Web.config file, 390
ProcessRequest method, 371request lifecycle events, 372–373SourceViewer.cs, 393SourceViewHandler class, 396System.Web.IHttpHandler, 371Web Form, 369
HandlerSelectionModule class, 434HandlerSelectionModule.cs file, 433Handling control events
AutoEventWireup attribute, 410register and apply, 412Render method, 411System.Web.UI.Control class, 409
■ index
1175
ViewCounter.ascx file, 410ViewCounter.aspx.cs code-behind file, 410Web User Control, 410
HeaderTemplate, 1013, 1034highlight class, 90HTML5 validation
checkValidity function, 1132CreateProduct.aspx file, 1131feature implementation, 1133input element, 1132price element, 1131required attribute, 1131script element, 1132setCustomValidity function, 1132
HtmlGenericControl class, 294, 783HtmlInputText class, 838HtmlTextWriter methods, 862–863HttpApplication.CompleteRequest method, 333, 339HttpApplication.Context property, 327HttpApplication object
completing requests, 333–334handling property exceptions, 332properties and methods, 331
HttpContext.AddError method, 576HttpContext.ClearError method, 573HttpContext.CurrentNotification property, 409HttpContext.Items collection, 391HttpContext.Items property, 390HttpContext methods, 432HttpContext objects, 330–331, 371, 374HttpContext.RemapHandler method, 434HttpContext.Timestamp property, 334, 341httpErrors element, 562HTTP redirection, 441HttpRequest.CurrentExecutionFilePathExtension
property, 379HttpRequest.FilePath property, 396HttpRequest.MapPath method, 396HttpRequest methods, 429HttpRequest object, 335–337, 371HttpRequest.RequestType, 435HttpResponse method, 534HttpResponse objects, 337, 339HttpResponse.Redirect method, 573HttpResponse.Write method, 405HttpServerUtility.Execute method, 573, 579HttpServerUtility methods, 432HttpServerUtility.Transfer method, 435
I���������IDataContainer interface, 1015id attributes, 1000IEnumerable<T>, 1025Ignore method, 649
IHttpHandler interface, 371, 403Immediate Window, 107IMonthProvider interface, 62Implicit typing, 53IncludeDirectory method, 1084InitComplete method, 415InnerText property, 998, 1002InsertProduct method, 1032InstanceControlFactory class, 383InstantiateIn method, 1015Integrated Development
Environment (IDE), 104Internet Information Services (IIS), 32IQueryable<Product>, 1024IQueryable<T>, 1025IRequiresDurationData, 392IRequiresSessionState, 403IRouteConstraint.Match method, 643IsAjaxRequest method, 377IsLiteralContent, 906IsPostBack property, 423IsPostNotification property, 328–329IsReusable property, 372Item.Name, 163ItemPlaceholderID attribute, 1043ITemplate interface, 1013Items collection, 392Items property, 998, 1005ItemTemplate, 1028ItemType attribute, 1004, 1011, 1024IValidatableObject, 955IYearProvider interface, 62
J���������JavaScript DOM manipulation library, 75JavaScript Object Notation (JSON)
Web API, 1101data
Default.js file, 97elements generation, 99HTML data elements, 97Name and Height property, 97$.parseJSON function, 98
jQuery, 115, 1137bundle, 1081CSS function, 90DOM, 80
manipulation functions, 92manipulation libraries, 80navigation functions, 91
element selectionattributes, 85filters, 86relationships and unions, 83Type, Class, or ID, 83
■ index
1176
Handling control events (cont.)
events, 94JavaScript function, 80JSON data, 96statements, 81
jQuery Mobile, 115jQuery UI, 115jqueryui bundle, 1081
K���������KeyValuePair class, 823Knockout library, 98, 116
L���������Lambda expressions
delegate definition replacement, 51delegate, extension method, 50filtering extension, 52filtering extension method with func, 50other forms, 53without func, 52
Language Integrated Queries (LINQ)deferred queries, 67dot notation, 66extension methods, 67OrderByDescending method, 66query data, 65querying without, 64query syntax, 65Select method, 66
LayoutTemplate, 1045–1046Lifecycles
application (see Application cycle)Default.aspx.cs file, 315EventCollection class, 314EventCollection.cs file, 313Events, 313GetEvents, 314Global Application Class, 315–316List collection, 314request (see Request lifecycle)
LinkButton controls, 1027, 1045LINQ. See Language Integrated Queries (LINQ)ListBox control
HTML, 1005–1006List.aspx.cs file, 1004List.aspx file, 1003properties, 1004select element, 1003–1004size attribute, 1003
ListControl class, 993–994Listing
contents ofcode-behind file, 130Web Form files, 130
product information, 131
ListItem control, 994, 1002ListItemDetails class, 1017ListView control
data validation, 1050events, 1048functionality
BindItem bindings, 1044CommandName attribute, 1043data display and editing, 1044declaring control, 1042EditItemTemplate, 1042, 1044Item binding, 1044itemPlaceholder, 1043ItemTemplate, 1042–1043LayoutTemplate, 1042–1043ListV.aspx file, 1040templates, 1042tr element, 1043
GetProducts and UpdateProduct methods, 1040ListV.aspx.cs file, 1040pagination, 1046sorting data, 1045ValidationSummary control, 1049
Literal control, 1015, 1065LiteralControl object, 906LoadComplete handler method, 952LoadControl method, 864LoadControlState method, 879Load event, 422LoadStateData method, 872–873Local optimization, 1085LogRequest, 343
M���������Manage NuGet Packages, 1075MapPageRoute method, 144, 168, 611, 689MapRequestHandler event, 321, 323, 372, 434MasterPageFile property, 420Match method, 643MaxPage property, 135Membership
adding to applicationadjusting configuration, 703attributes defined, 701authentication using membership, 705creating users and roles, 704installing universal providers, 698setting up membership, 699
administration tool, 721methods defined, 706password change
adding link to change password, 711authentication, 710code-behind class for Web Form, 709contents of Web Form, 708
■ index
1177
password recoverycoding, 712content of Web Form, 711integrating into password change, 714multistage recovery process, 713–714
project preparation, 697properties and methods defined, 707registration
assign user to roles, 720content of Web Form, 716create user account, 718integrating registration, 721processing form data, 717
Merged configuration, 727Microsoft library, 98Mobile devices
configuring packages, 1158custom content delivery, 1159definition, 1149identification, 1152installing packages, 1158for jQuery mobile package, 1150master page
JavaScript libraries, 1157Simple.aspx.cs file, 1156Site.Master file, 1154Site.Mobile.Master file, 1155
MobileModule.cs file, 1162Simple.aspx file, 1149Simple.aspx Web Form, 1150ViewSwitcher control, 1160Web.config file, 1163
Model binding, 952Age property, 934complex types, 953Controls/OperationSelector.cs file, 948CustomChecks.cs file, 939custom validation method, 939Data.aspx.cs code-behind file, 950–951, 953Data.aspx Web Form file, 949Default.aspx.cs file, 933, 935–936, 954Default.aspx file, 932, 953, 957field-level error controls, 956FieldValidator control, 957FieldValidator.cs file, 956FormatException, 936form data values, 934FormValueProvider class, 937, 947input element, 949, 951IValidatableObject interface, 955IValueProvider implementation classes, 948LoadComplete method, 950Models/Person.cs file, 931, 938, 940, 955model validation, 938Name property, 934
OperationSelector control, 949–950Person class, 931Product class, 931project preparation, 931properties for validation, 938Repeater control, 949self-validating model classes, 955System.Web.ModelBinding, 947System.Web.ModelBinding.IValueProvider, 947TryUpdateModel<T> method, 937and validation errors
Default.aspx.cs file, 942, 946Default.aspx file, 940, 944GetModelValidationErrors method, 941, 943IsValid property, 943ModelError class, 943ModelState class, 943ModelStateDictionary class, 943PlaceHolder control, 941Repeater control, 941ValidationSummary control, 944, 946–947
value providers, 937, 947ModelBindingExecutionContext class, 937ModelStateDictionary, 943Model-View-View-Model (MVVM), 116Modernizr, 116Modules
BeginRequest event, 367built-in modules
ASP.NET Framework Application, 364CommonModules classes, 363Context.ApplicationInstance property, 362ListModules.aspx.cs code-behind class, 361ListModules.aspx file, 362ListModules.aspx Web Form, 363Start and End events, 361
creationASP.NET Module item template, 347HttpApplication instance, 348HttpApplication.LogRequest event, 348ParamsModule.cs file, 347PostAuthenticateRequest, 348registration, 349
en-GB locale, 367Events project, 345global application class, 346Global.asax.cs file, 346HttpApplication class, 346HttpApplication object, 347Init method, 347LocaleModule.cs file, 366module events
AverageTimeModule class, 356AverageTimeModule.cs file, 355, 358declarative handler, 360EventCollection class, 359
■ index
1178
Membership (cont.)
Global.asax.cs file, 359HttpModulesCollection object, 356name attribute, 360RequestTimed, 355TimerModule class, 356TimerModule.cs file, 354Web.config file, 357, 360
Params.aspx Web Form, 346Price.aspx file, 366System.Web.IHttpModule interface, 347Visual Studio project
BeginRequest and EndRequest events, 352CommonModules, 350Default.aspx, 353HttpContext.CurrentNotification, 352HttpContext.TimeStamp property, 352LogModule.cs file, 351ModuleRegistration.cs file, 352Params.aspx Web Form, 353PreApplicationStartMethod, 353RegisterModules class, 353System.Web assembly, 350TimerModule.cs file, 351Web.config file, 352
Web.config file, 367MultiView control, 1068MVC framework, 31MyAsyncMethods class, 70MyContainers.cs file, 56MyDataMethod, 1024MyExtensionMethods class, 46
N���������Name property, 163Nesting Master Pages, 308–311.NET Framework Source Stepping, 104NextPreviousPagerField control, 1047NotRemovable value, 504NuGet
dependency management, 112, 114jQuery.Validation package, 113Microsoft jQuery Unobtrusive
Validation package, 112–113package installation, 114SportsStore, 195
NumericPageField, 1047
O���������Odds-and-ends controls
literal controls, 1065MultiView control, 1068PlaceHolder control, 1066
OnBubbleEvent method, 1059Opera Mobile, 114
OperationSelector control, 952OrderByDescending method, 66OrderBy method, 133Orders property, 185Outer table, 1028
P���������Page context
Context.ApplicationInstance property, 419convenience properties, 419IsPostBack property, 421page directive values, 420Web Form, 419
Page/Control lifecycle events, 1000Page event
ASP.NET Framework, 403code-behind class, 403EventCollection.Add method, 402EventCollection class, 401EventSource enumeration, 402Events project, 401Global.asax.cs file, 401–402handler factory, 404, 406IHttpHandler interface, 403–404IRequiresSessionState, 403lifecycle
declarative handlers, 407–408HTML response, 406Render method, 409System.Web.UI.Page class, 406Web Form code-behind class, 407
PageHandlerFactory class, 403PreRequestHandlerExecute, 402
PageHandlerFactory class, 403, 405Page Inspector tool
advantage, 108Inspect, HTML, and Files buttons, 108Internet Explorer 10, 108layout, 107–108
Page_Load event, 413Page_Load method, 15, 294, 296, 415, 678, 794Page.ModelState property, 942, 957PageSize attribute, 1047Pagination
add pagination links, 135empty product pages, 135page of products, 132pagination code test, 133update GetProducts method, 134
Params.aspx file, 336Params.aspx Web Form, 341PartyStyles.css file, 12Password change, 708Password recovery, 711Path rewriting, 590, 594
■ index
1179
Pathscreate Web Form, 602get path information
additional path information, 587fixed and dynamic path information, 585HttpRequest class, 584
manipulation, 588physical path, 583project
additional content, 583Default.aspx file, 581modules, 582
rewriting paths, 603tilde (~) character, 584virtual path (see Virtual paths)
PerformDataBinding method, 974–975, 978PlaceHolder control, 1066PostAcquireRequestState event, 323, 372, 482PostAuthenticateRequest event, 341PostBack.aspx file, 422PostBack.aspx.cs code-behind file, 423PostMapRequestHandler event, 323, 372PostRequestHandlerExecute event, 372, 390, 393PostResolveRequestCache event, 434prepend function, 93prependTo function, 93PreRenderComplete event, 409PreRequestHandlerExecute event, 372, 402PreSendRequestHeaders, 322ProcessContainerControl method, 906ProcessRequest method, 371–372, 374, 376, 545ProductID attribute, 1042ProductID property, 1033, 1035, 1046Product model class, 1011Product objects, 1025ProductTest.aspx file, 1105Property code nuggets, 290–291PropertyName property, 957
Q���������Query syntax, 65
R���������RadioButtonList control
HTML, 1007–1008input elements, 1006–1007label element, 1007Radio.aspx.cs file, 1007Radio.aspx file, 1006
Receiving control eventsdeclarative handler, 416–417Default.aspx.cs file, 414Default.aspx file, 415
desktop-like development style, 413InitComplete method, 415Page_Load event, 413Page_Load method, 415ViewCounter.ascx.cs, 413ViewCounterEventArgs object, 414
Recycling.cs, 385Recycling handlers, 385–387RegisterBundles method, 197–198, 1022, 1079Registering controls
Register directive, 842runat attribute, 843user control, 844Web.config file, 844
RegisterRequiresControlState method, 878–879RegisterRoutes method, 144–146, 609RegisterScripts method, 1022ReleaseHandler method, 387ReleaseRequestState, 322RemapHandler method, 434, 443, 645remove element, 564RenderChildren method, 1059RenderContents method, 957, 975RenderEndTag method, 863Render method, 409, 411RenderOuterTable attribute, 1028Repeater control, 162–163, 951, 953–954
GetProducts method, 1011ItemType and SelectMethod attributes, 1010Repeat.aspx.cs code-behind file, 1011Repeat.aspx Web Form, 1010templates, 1012
highlighting alternate table rows, 1013programmatic technique, 1013Repeat.aspx file, 1012
Repository class, 184, 1101Repository.SaveProduct method, 1037Representation State Transfer (REST), 1101RequestCountDependency.cs, 497Request handling, asynchronous See Asynchronous
request handlingRequest lifecycle, 372–373
handlers, 323handling methods
Application_BeginRequest, 325Application_EndRequest, 325Declarative event handler, 325EventCollection.Add method, 325Global.asax.cs code-behind file, 324MapRequestHandler, 323multiple events, 326–327, 329PostMapRequestHandler event, 323PreRequestHandlerExecute, 326System.Web.IHttpHandler, 323
HttpApplication class, 321module, 322
■ index
1180
Request processingAjaxSourceModule.cs, 442–443applications, 425–426BeginRequest event, 443handler selection and execution
Execute method, 438–439HttpContext methods, 432HttpServerUtility methods, 432preempt handler selection, 433–435Transfer method, 435–437
RemapHandler method, 443side-by-side handler, 447, 449source handler, 446–447SourceViewHandler.cs, 439, 441URL redirection
content page, 428CurrentTimeHandler, 430Default.aspx file, 429HttpRequest methods, 428manually performing redirection, 431Redirect/RedirectPermanent method, 430301 status code, 428302 status code, 428web application development, 428
Web.config file, 443Web Form, 444
HTML display and markup, 449HttpContext.Items collection, 446Page.Items collection, 446SxSView.aspx, 444
Request validationcode-behind class, 829controls, 835definition, 828eager validation, 829input elements, 828lazy validation, 831SQL injection, 832unvalidated data
ASP.NET, 834code nugget, 834HttpRequest class, 834HttpRequest.Unvalidated.Form collection, 832script element, 835UnvalidatedRequestValues class, 833Web Form response, 835
Valid.aspx file, 828requireJS library, 116ResolveRequestCache, 321Response property, 168Response.Redirect method, 168ResponseRepository class, 10Response.Write method, 284Routing segment variable, 145Rows attribute, 1004–1005RowTemplate, 1015
S���������SaveControlState method, 879SaveOrder method, 185SaveStateComplete event, 409SaveStateData method, 872Script and style management
bundle optimizationcontent delivery networks, 1093file duplication issue, 1088local optimization, 1087profiling browser requests, 1086relative image issue fixing, 1090
bundlesBundleConfig.cs, 1079definition, 1079project preparation, 1080script creation(see Script bundle)style bundle creation, 1085
CdnInclude method, 1096CdnScriptBundle.cs, 1095data controls, 1095project preparation, 1077script management issues
JavaScript file versioning, 1078JavaScript library, 1077library dependencies, 1078minification, 1078–1079
Script bundlecreation, 1081duplication avoidance, 1083Include method, 1081jQuery script file, 1081System.Web.Optimization.Scripts.Render
method, 1081ScriptConfig class, 1022ScriptManager class, 1022, 1093SecondPage.aspx, 426SelectedIndex property, 998SelectedItem property, 998SelectedValue property, 998, 1002, 1007SelectionControl.cs, 384SelectionControlFactory class, 385SelectionMode attribute, 1004–1005SelectMethod attribute, 1024, 1029, 1032, 1039, 1042SelectMethod data method, 1027Server controls, 162
BasicCalc.ascx file, 857ButtonCounterServerControl.cs File, 788creation, 201Custom/ServerCalc.cs file, 857, 859Default.aspx file, 790–791ErrorMessage values, 204–205HtmlTextWriter class
constrained HTML method, 862unconstrained HTML, 863
■ index
1181
HtmlTextWriter methods, 790/Pages/Checkout.aspx Web
Form file, 203register, 859Register directive, 791RenderContents method, 789, 859Required attribute, 204VInput, 203WebControl class, 789
Server-side HTML elementsbase class features, 902
BaseClass.aspx.cs file, 903BaseClass.aspx file, 902CSS approach, 903HtmlControls class, 902properties and methods, 902System.Web.UI.HtmlControls, 902Visual Studio Output window, 903
container elementsContainer.aspx.cs code-behind file, 905Container.aspx.cs file, 906Container.aspx file, 905content of, 906HtmlContainerControl class, 904, 906InnerHtml property, 904, 906InnerText property, 906–907InnerText value, 904IsLiteralContent, 906LiteralControl object, 906ProcessContainerControl method, 906properties, 904
control classes, 927HtmlButton control, 917HtmlSelect control, 917–918HTML tables, 919
cell values, 922contents of table cells, 923control classes, 920CreateTable.aspx.cs file, 925, 928CreateTable.aspx file, 925, 927HtmlContainerControl, 922HtmlRow.Cells properties, 922HtmlTableCell objects, 920, 922HtmlTableRow.Cells property, 920HtmlTableRow objects, 920HtmlTable.Rows, 922InnerText property, 922Load event handler method, 922, 926Rows property, 920SimpleTable.aspx.cs file, 921, 923SimpleTable.aspx file, 920specific table elements, 923tr, th, and td elements, 923
HtmlTextArea control, 917
input element, 909control classes, 912CreateForm.aspx.cs code-behind file, 914CreateForm.aspx file, 913Form5.aspx.cs code-behind class, 915Form5.aspx file, 915HTML5 form features, 914HtmlInputControl class, 910, 914HtmlInputGenericControl class, 914, 916in Internet Explorer 10, 916Page.Form property, 911SimpleForm.aspx.cs file, 910SimpleForm.aspx file, 910type-specific control classes, 912
Items property, 917page structure elements, 907
control classes, 909html and meta elements, 908HtmlHead class, 908Structure.aspx.cs file, 908–909Structure.aspx file, 907
project preparation, 901Repeater control, 927–928Select.aspx.cs file, 919Select.aspx file, 918
Server-side validation, 195. See also Client-side validationSession property, 165, 167Session state objects, 165Set method, 166Shopping Cart
basic cart flow, 159cart buttons
add cart button CSS, 164data binding, 161data method public, 163server controls, 161Web Form, 161
Cart class, 160display cart contents, 168form post, 167session helper, 164test cart, 171
ShoppingCart class, 44ShowFirstPageButton attribute, 1047ShowLastPageButton attribute, 1047ShowNextPageButton attribute, 1047ShowPreviousPageButton attribute, 1047SimpleState.aspx File, 886–887SimpleTime control, 885sInsertProduct method, 1037size attribute, 1003Skip method, 133Smart user interface (Smart UI), 33SourceViewer.cs, 393SourceViewHandler class, 396
■ index
1182
Server controls (cont.)
SportsStoreadd category information (see Category)add repository class, 129ASP.NET Empty Web Application template, 117authorization
administration pages securing, 224/admin/orders URL, 229authentication login Web Form, 225failed authentication testing, 227Web.config file, 228
building blocksAdmin Master Page addition, 208ContentPlaceHolder, 208CSS Style Sheet, 209MasterPage class, 209OrdersUrl and ProductsUrl, 209routing configuration, 207System.Web.UI.MasterPage, 209Web Form addition, 210
cart summarycategory navigation widget, 177control, 179/Controls/CartSummary.ascx.cs file, 178CSS styles, 179DOM API, 179HtmlAnchor class, 178HtmlGenericControl class, 178id attribute, 178/Pages/CartSummary.ascx
web control file, 178runat attribute, 178user control declarations, 180Web User Control, 177
catalog managementAdd button, 224CRUD methods, 221Edit button, 223ListView control, 218Repository class, 218Update button, 224Web Form addition, 220zero ProductID values, 219
databaseadd data to, 125creation, 121database schema, 123
data model classadd Entity Framework, 127creation, 126Entity Framework context creation, 127
design goal, 138folder structure, 117global application class, 119master page
apply, 140creation, 138
customize, 139test, 141
order management/admin/orders, 217bool parameter, 217CheckBox control, 215Control attribute, 217Database cleansing and populating, 212Data-Binding Expressions, 214Dispatch button, 214GetOrders method, 217Orders.aspx file, 212Orders.aspx Web Form, 214Page_Load method, 217/Pages/Admin/Orders.aspx.cs, 216PlaceHolder control, 215Repeater control, 213SelectMethod attribute, 217Total method, 217Visible property, 215
order processCartLine and OrderLine objects, 191Checkout.aspx file contents, 188completion message, 193CSS styles, 189IsPostBack property, 191model binding, 191/Pages/Checkout.aspx file contents, 190runat attribute, 189shipping details form, 192Visible property, 191
order submissionadding data model classes, 183checkout link and URL, 185context and repository classes, 184database and data model extension, 181
pagination (see Pagination)product listing (see Listing)removing unwanted cart items
HTTP POST request handling, 174Remove buttons, CartView.aspx, 173view state (see View state)
Shopping Cart (see Shopping Cart)URL routing (see URL routing)validation
applying server control, 203attribute addition, 193client-side validation, 195, 199creating server control, 201ErrorMessage property, 194NuGet packages, 195package updation, 196Required attribute, 194script bundle, 197server-side validation, 195TryUpdateModel method, 195
■ index
1183
SportsStore application, 1100SportsStore deployment
applicationAzure service configuration, 240–241database connections, 242Publish Web dialog box, 240, 242–243Visual Studio Output window, 244Windows Azure platform, 245
ASP.NET Framework application, 231Azure
database tables creation, 238Data Explorer Window, 237MSDN packages, 232portal, 233remote administration, 236SQL command, 237table data, 238–239web site and database creation, 233–235
disabling debug mode, 231Standard code nuggets, 284State collisions, 871State data
application, 451ASP.NET Framework, 452connectionStrings element, 458–459cookies
CityAndColor.aspx.cs code-behind file, 485
CityAndColor.aspx Web Form file, 483Default.aspx.cs code-behind file, 480DropDownList control, 484GetColors and GetCities methods, 485HttpAppliation.Session property, 483HttpContext.Session property, 483HttpCookieCollection class, 480Page.IsPostBack property, 486Request.Cookies, 480Response.Cookies, 481StateModule.cs file, 482
profile data, 456–457Default.aspx.cs code-behind file, 464Default.aspx Web Form, 463Page_Load method, 464ProfileBase.Create method, 464Save method, 465
profile feature configuration, 459profile properties, 461–462profile providers, 460–461session data
configuration, 470–471Default.aspx Web Form, 466GetProfileCounter method, 467GetSessionCounter method, 467HttpSessionState class, 469queuing issue, 469SQL Database, 473–476
StateServer, 471–473System.Web.SessionState.HttpSessionState
object, 466user profile data, 468
store application dataApplication property, 454Default.aspx.cs code-behind file, 453HttpApplicationState class, 454Lock method, 455UnLock method, 455
view state dataconfiguration, 478–479Default.aspx.cs code-behind file, 477Default.aspx file, 477StateBag class, 478uses, 477
Visual Studio Database Explorer window, 457STCacheObject.cs file, 511StopRoutingHandler class, 648StopRoutingHandler method, 649StringContainer class, 56–57String.Join method, 998String.Split method, 857Strongly typed data controls, 163SuppressContent property, 338SxSHandler.cs file, 447Synchronous request processing, 763System.ComponentModel.DataAnnotations, 940System.Diagnostics.Debug.WriteLine method, 314System.Net.Http namespace, 70System.Web.Caching, 496System.Web.Compilation, 404System.Web.HttpApplication, 317System.Web.IHttpHandler, 371System.Web.IHttpModule interface, 322System.Web.ModelBinding.IValueProvider, 937System.Web.Optimization.Scripts.Render method, 1081System.Web.RequestNotification, 329System.Web.RouteTable class, 146system.webServer element, 380System.Web.UI.HtmlControls, 294System.Web.UI.Page class, 297, 403System.Web.UI.WebControl.ListItem objects, 917
T���������TagName property, 927Take method, 133, 387Testable Web Apps
business logic, 248Default.aspx.cs code-behind file, 247dependency injection
configuration, 273Default.aspx.cs file, 270MemoryRepository classes, 271Ninject package, 271
■ index
1184
DI configuration entry, 277GetResponses method, 275IPresenter<IEnumerable<GuestResponse>>, 276Model-View-Presenter (MVP)
components of, 249elements selection, 249
PartyInvitesadding folder structure, 250/Content/PartyStyles.css file, 251/Content/seeyouthere.html file, 251/Content/sorryyoucantcome.html file, 251DataResult class, 255GetRepository method, 253GetResult method, 254GuestResponse data objects, 253Interface template item, 252IRepository.cs interface, 253IResult interface, 254MemoryRepository.cs, 253/Models/GuestReponse.cs class file, 252Models/Repository, 251Presenters/Results, 251RedirectResult constructor, 254–255
request-and-response code, 248RSVP page
business logic, 256Debug menu, 259Inherits attribute value, 258IPresenter<GuestResponse> interface, 256IPresenter<T> interface, 256Page directive, 258/Pages/Default.aspx.cs code-behind file, 258/Pages/Default.aspx file, 257PartStyles.css file, 258RSVPPresenter class, 255
RSVPPresenter class, 276SetupDI methods, 277Summary.aspx file, 248, 275unit testing
Adds_Object_To_Repository, 264Assert.AreEqual method, 264input values, 265project creation, 260RSVPPresenter class, 263RSVPPresenterTests.cs file, 262static assert methods, 265UnitTest1.cs file, 262Visual Studio Test Explorer dialog box, 265
Time.asxh, 374TimeProvider class, 62–64Top.Master, 308ToString(“c”) method, 130TotalDurationModule class, 392–393TotalDurationModule.cs, 389Transfer method, 436
TryUpdateModel method, 15, 1038TryUpdateModel<T> method, 937–938, 942, 948, 1037Type inference, 53
U���������UI controls
C# events, 1054command pattern
Commands.aspx Web Form, 1059Counter control, 1059Counter.cs file, 1057CreateChildControls method, 1059implementation, 1060OnBubbleEvent method, 1059RenderChildren method, 1059templates, 1062
cross-page postingFormOne.aspx Web Form, 1062FormTwo.aspx Web Form, 1063
CssClass control, 1055CSS properties, 1054Default.aspx Web Form, 1051EventArgs object, 1056handler method, 1056href attribute, 1054HTML element, 1053HTTP request, 1056ID, 1057input elements, 1053ItemCommand event, 1071LinkButton control, 1052–1054OnClick attribute, 1056On<EventName> attribute, 1056RepeaterCommands.aspx.cs file, 1071RepeaterCommands.aspx
Web Form, 1070–1071selection, 1055server-side span element, 1052style attribute, 1055web application creations, 1051
Universal providers, 698Update callback handler method, 509UpdateMethod attribute, 1042UpdateProduct method, 1037URL, 185URL routing, 589–590
Application_Start method, 609App_Start/RouteConfig.cs class file, 608ASPX requests, 657base and wrapper classes, 643BeginRequest event, 632constraints(see Constraints)count segment, 629custom RouteBase implementation
■ index
1185
BrowserRoute, 656BrowserRoute.cs file, 655GetRouteData method, 656GetVirtualPath method, 657Loop.aspx Web Form, 657Route class, 654RouteData object, 656
diagnostic HTML, 633file request
default configuration, 645disabling file routing, 646handlers /modules, 644project files, 645RouteCollection class, 646
file typesconstraint class, 665CustomHandler.cs file, 660GenHandler.ashx, 659outgoing URLs, 663registering, 662route handler, 661route order, 665
global application class, 608Global.asax.cs class file, 609handlers
ASP.NET framework, 648custom route handler, 652dynamic object, 652GetTest.aspx code, 650–651HttpMethodConstraint object, 651Ignore method, 648, 652POST method, 650RouteCollection class, 648Route constructor, 652routing configuration, 649–650StopRoutingHandler class, 648–649
model binding system, 626modules and handlers, 645outgoing URLs
/App_Start/RouteConfig.cs file, 630contents of, 629form element, 630GetRouteUrl method, 631
pagination links, 143project preparation, 607–608, 639RegisterRoutes method, 609request, 143routed links, 148RouteMatchInfo class, 635RouteTestModule.cs file, 632routing configuration class, 144routing variable, 146Store folder, 143testing route matching, 637
test routing configuration, 147update global application class, 146variable segments
/App_Start/RouteConfig.cs file, 615constraints, 617Dall Route, 617default values, 623hackable URLs (see Hackable URLs)modification, 616over-eager route, 617reordering, 617System.Web.Routing, 616variable-length segment, 625
virtual pathcart2 route, 612fixed routes, 612flexibility, 611GetURLFromRoute, 613implementation, 613–614MapPageRoute method, 611RouteBase class, 613Routeclass, 614RouteCollection.MapPageRoute method, 610RouteData class, 613routing configuration, 612Url property, 615
Web.config file, 633Users.apsx, 310
V���������ValidateRequest attribute, 830ValidateRequestMode property, 420ValidationContext object, 955ValidationRepeater.cs file, 1142ValidationResult objects, 940, 956ValidationSummary control, 194, 200, 944–945ValueContainer class, 60ViewCounter.ascx.cs, 413ViewCounter.ascx file, 410ViewCounter.aspx.cs code-behind file, 410ViewCounterEventArgs object, 414View Markup, 374View state
browser F12 tools, 176disabling, 176Remove buttons unexpected behaviour, 175Repeater control, 176
ViewStateEncryptionMode property, 420ViewStateMode attribute, 792ViewStateMode property, 420VInput server control, 203Virtual paths
default documents, 590default mapping, 589
■ index
1186
URL routing (cont.)
definition, 583direct mapping, 589extensionless URL, 592features, 590friendly URLs package (see Friendly URL)path rewriting, 594vs. physical paths, 584tilde (~) character, 584
Visual Studio debuggerapplication state, 106breaking, 103breakpoints
conditional, 104creation, 103FormData object, 103IDE, 104.Net framework source code, 104
Immediate Window, 107Visual Studio project
adding jQueryNuGet package manager, 77Web Form, 79
Default.aspx file contents, 76HTML and CSS appearance, 77Styles.css file contents, 76
W���������Web.config file, 379, 405, 434, 440, 499, 510WebControl class, 789Web Form ASPX file, 441WebFormHandlerFactory class, 406WebFormHandlerFactory.cs, 404Web Forms, 30, 33, 369
App_Web_nwbfdcye.0.cs, 300ASP.NET Framework application, 281–282ASPX file extension, 281code-behind classes
ASP.NET Framework features, 295CodeBehind attribute, 296CommonPageBase.cs, 296Default.aspx.cs, 295Default code-behind class, 296GetDayOfWeek method, 297Page_Load method, 296System.Web.UI.Page class, 297
code nuggetsdata binding, 287–289content, 284–287directive, 291–292property, 290–291
standard, 284types of, 283
components/controls, 33, 295CS file extension, 282C# statements, 302default_aspx class, 301Default.aspx.cs code-behind file, 298Default.aspx file, 281, 298DESIGNER.CS file extension, 282dynamic compilation, 299event handlers, 33master pages
Basic.Master, 303code-behind class, 306–307Colors.aspx.cs code-behind file, 305Content control, 306ContentPlaceHolder controls, 304GetColors method, 306Master directive attributes, 303MasterPageFile, 305nest, 308–311Web Form using Master Page
template item, 305programmable HTML elements, 293–295, 299smart user interface, 33–34strength
quickest and easiest method, 35recruit talent easy, 35widely support, 35
Visual Studio project, 281weaknesses
bandwidth-heavy view state, 36low developer mindshare, 36poor maintainability, 35poor unit testability, 36
WebHandler directive, 374Web User Control, 410Windows Azure platform, 245Write method, 374, 863
X���������X-Requested-With value, 376
Y���������Yellow screen of death (YSOD), 554
Z���������Zombie control state, 870
■ index
1187
top related