ASP.NET 4.5, Under the Cover

Thursday, May 22, 2014

File new project, empty web application

Add this static helper class, within this static method that writes a string to the current response object

Add a web form, in page load event, invoke the static helper method

View the page in the browser, the contents are rendered on the screen

Add a global application class to the project

Type in this code to calculate time it takes to process the request

Add a webform to the project, type in this markup

Delay the response by 2 seconds with this line of code

Launch the default page and view the page processing time in the browser, less than one millisecond

View page1 in the browser, it has the lag of 2 seconds

Now let's build a custom handler, in global application class comment out the response write

Add this anchor tag, notice the csv extension

Add this class, implement the ihttp handler interface

Type in this code, this a valid handler, an endpoint

Add this httphandler configuration in web.config, wire up the path to the endpoint

Launch the default page, click get data link, prompt open file in excel

View the csv list in excel

Add a generic handler to the project

View the implementation has already been stubbed out

In default page reference ashx file in the anchor tag

Launch default page, click link and view results rendered on the screen

Add this class, have it derive from the interface ihttpmodule

Type in this code, event handlers and delegates to handle the request, copy in the code from global application class, modify the key

Add the module in the web configuration file, specify type attribute namespace and assembly name

View page in browser, now getting the render time from the httpmodule instead of the global application class

File new project, empty web forms web application

Add a webform and type in this markup, in page directives set trace to true

Run page in browser, view the control hierarchy

Type in this markup for basic addition calculator func into default page

In button click event type in this calculation logic

View page in browser, enter some numbers, click calculate, view the result

Add a user control to the project

Paste in the markup from default.aspx into the user control

Cut and paste the buttoncalculate function in code behind of user control

Drag the user control onto the web form, design surface

View page in browser, enter some values, click button, verify calculator still works

Add this label inside the legend tags of the user control

In code behind, type in these properties, instantiate them in the constructor and set the in page load event

In web form on properties window set the font size and labeltitle text properties

View page in browser, a much bigger font and title has been changed

Default Success Warning Important Info Inverse
B S W I ? O