Tuesday, March 30, 2010

.NET 4 ASP.NET ‘Developing Web Forms Pages’ 70-515 Exam Prep ASP.NET – Catto Code Crackin #13

Hey Now Everybody,

.NET 4 ASP.NET ‘Developing Web Forms Pages’ 70-515 Exam Prep ASP.NET – Catto Code Crackin #13

Hey Now Everybody,

In this 13th post of the Catto Code Crackin series we’ll continue with the section ‘‘Developing Web Forms Pages’. This is the first section in the objectives but it’s the last one I chose to cover. In the .NET 3.5 Configuring and Deploying Web Applications (10 percent). In the .NET 4 exam the section is listed as ~19%.

Microsoft announced the .NET 4.0 Beta Exams on St. Patrick’s Day which are a free exam & if passed you get certified. Much of the study & prep materials are not available yet, therefore I’ve been studying for a similar exam 70-562 which is the .NET 3.5 ASP.NET Application Development. I hope by posting this content it will help myself along with other people in the community learn & get excited about .NET 4. If you are serious about studying for a MS Exam 2 must have resources: the Microsoft Self Paced training books are a great books to buy along with practice exams from eBay

.NET 4 - Key Objectives

Configure Web Forms

Implement Master pages & Themes


Page Life Cycle


Managing State

Here are the official skills measured for the 70-515:

Developing Web Forms Pages (19%)

Let’s continue with some key points on these topics from the 3.5 book:

Master Pages:

Master pages provide templates that you can use to create consistent web pages though out an app.

To use master pages, create a master page & add site layout info & other common elements. Add 1 or more multiple ContentPlaceholder controls to the master page.

To create the content pages, add standard web forms to our site and select the Select Master Page check box when creating the page. Then add content inside the content placeholder control.

To reference public properties in a master page, add the @ MasterType declaration to the content page & reference the property using the Master<propertyname> to reference controls in a master page call the Master.FindControl from the content page.

Nested Master pages fit into the ContentPlaceHolder controls on a master page but can contain other content pages. To create a nested master page, add a master attribute to the @ Master page declaration & specify the parent master page.

To programmatically change the master page for a content page, set the page’s MasterPageFile property & reload the page.

Web parts

Web parts are controls that you create using custom controls that implement the web part class or stand user controls & ASP.ENT contrls. Web Parts are aslo managed b ASP.NET which allows users to close , minimize, move & edit them.

To enable users to edit or rearrange eb parts, you change the displaymode property of the webPartManager contrl on our page

Web Parts can be connected to enable them to share data. We do so by defining both consumer & provider web parts using the attribute-based programming medel Also we configure the connections between web parts by adding a <staticConnections> element in the WebPartManager contorl

To add web parts to a page add a WebPartManager control to the top of the page add WebPartZone containers to the page & then add controls to the WEbPartZone Containers.

Themes 5.2

To create a theme add an App+Themes subfolder to our app. Then for each theme in your site add a folder. The folders name becomes the name of your theme. Blog Engine .NET is a good example of this.

Themes contain skin files, a style sheet, images & other resouces.

We can apply a theme at the page level or site level thought the web.config at the individual control level.

Intrinsic Objects:

You can use the Request object to examine detail of the client web browser’s request to the web server, including the request headers, cookies client certificate, query string & more. You can use the Response objecdt to send data directly to the client w/out using standard ASP.NET server controls. You can use Server object’s static methods to perform of HTML & URL data. The context object provides several unique methods for adding errors & enabling debugging.

You can use the Browser object to determine the client Web Browser type & whether it supports cookies, ActiveX, JS, & other capabilities that can affect its ability to render your web pages correctly.

Use the Page Header.StyleSheet object to dynamically set the page style sheet including info such as the bg color & use the Page.HeaderTitle object to dynamically set the page title

Business Objects & Utility classes

ASP.NET 3.5 supports the file system web site type. This is good option when IIS is not installed on the dev’s pc & the developer wants to create a Web site w/out the use of remote web server.

ASP.NET 3.5 supports the FTP web site types. This option can be used when building a web site that is being hosted on a remote pc that does not have front page server extensions installed.

ASP.NET 3.5 supports the HTTP web site type. This option is a good choice when IIS is installed on a dev’s pc or on a remote server w/ Front Page Server extensions installed.

FTP in ASP.NET 3.5 active mode is the default. However, passive mode can solve communication problems when the client has to go through a firewall.

ASP.NET supports 2 programming models for pages. Single file & code behind . With the single file programming model all of the web page markup & code are in a single file. With the code behind model, the server side code is separate from the markup & put into a separate file such as.cs or .vb.

In ASP.NET 3.5 dynamic complication refers to the delayed complication of pages that taks place when a user requests a page.

ASP.NET 3.5 defines several folders. When a new site is created, the App_data folder is created by default. It can contain a SQL Server database, XML data file that will be used in the site.

A browser is used to make requests to a server. It renders HTML to the user, collects data from the user, & sends data back to the server. The server is responsible for accepting a resource request & sending the appropriate response. The communication between browser & server is done via the text-based communication protocol HTTP.

ASP.NET 4 supports 3 web site types: file system, FTP & HTTP

ASP.NET 4 supports two programming models for pages: single file & code behind

Visual Studio allows us to select a programming language for each web page.

ASP.NET 4 uses a hierarchy of config files that can be modified to manage the settings of an app.

ASP.NET pages have a defined cycle that determines how ASP.NET will process the page, call events, & collect data to the page.

ViewState is the mechanism by which web page object & child control object data can be maintained between page request.

A server control is a control that is programmable by writing server-side code to respond to events from the control.

Server controls contain runat=”server”

State Management

Use client side management when scalability is the top priority Use of server side state management when data must be better protected or when bandwidth is a significant issue.

ASP.NET uses view state by default to store info about controls in a web form. We can add custom values to view state by accessing the ViewState collection.

Use control state when a custom control cannot function with view state disabled.

Use hidden fields to store data in forms when view state is disabled. Hidden fields values are available to users as plaintext in the HTML.

Cookies store data on the client that the web browser submits with every web page request. Use cookies to track users track users across multiple pages.

Query Strings store small pieces of info in a hyperlink’s URL. The query strings when you want state management data to be bookmarked such as displaying multiple pages of search results.

Web site programmability

You can catch unhandled exceptions at the page level by responding to Page_Error or at the app level by responding to Application_Error. In either event handler, you read the last error by calling Server.GetLastError. Then you must remove it from the queue by calling Server.ClearError.

You can call WEbConfigurationManager.GetSection to return a configuration section from the web.config file. You cast the returned object to the section specific type. If you make an update to the conf strings write the changes by calling configuration.Save or Configuration.SaveAs

Config App Pools & Compile Application;
Deploying, Configuring & Cashing Applications

Web setup Project allow us to create executable setup.exe files & windows installer packages (.msi ) that admins can use to easily deploy our apps to a server

The copy web tool can synchronize a web site between a server & our local pc. This is useful if we want to do deployment testing on our local pc and then upload the website to a server. The copy web tool can also be useful in environments with multiple developers since it detects versioning conflicts.

Precompiling a web app removes the delay that occurs when a ASP.NET compiles an application after the first user request. Use the web site publish tool to precompile a web app. The web site publish too l in located in the build menu. We then select the destination such as FTP or local IIS. There are a couple of options worth noting for this such as the ‘Allow this precompiled site to be updated, ‘use fixed named & single page assemblies’ & ‘enable strong naming on precompiled assemblies’

’We can use the Cashe object to store data of any types. You can then access the cached data from other web pages in our app. The cashe object is an excellent way to reduce the # of db’s calls & file reads. Use the Cashe Add & Cashe.Insert methods to add an object to the cashe with dependency to ensure the cashed object does not become stale.

Page output cashing stores a copy of rendered page in the servers memory. Subsequent requests for a given resources are served from memory page Output caching practically eliminates rendering time.

User Profiles, Authorization, Authentication

We can configure user profiles using the web.config file & the <profile> element. We add fields to this element based on which data elements we intend to track users on our site.

ASP.NET automatically creates strongly typed objects based on our profile filed settings in the web.config file. We can access this calss & it’s properties through the Profile <fieldname> syntax in our code.

We call the profile.Save method to save users profile to the db

By default, ASP.NET uses the SQLProfileProvider to store & retrieve user profile information to a SQL Server db called aspnetdb.mdf . We can change the db to connect to a SQL Server db by eding the connection strings.

Exam Questions Concepts:

1 - Unless you specifically narrow the scope, the user's browser submits information stored in a cookie to every page on your site. Therefore, each page processes the user preference information. If you configure the cookie expiration to make it persistent, the browser submits the cookie the next time the user visits your site.

2 - Storing user name & password. Server-side state management provides better security for confidential information by reducing the number of times the information is transmitted across the network.

3 When you have a web part and want another web part to connect to it you should apply the ConnectionProvider attribute to a public method to allow consumers to access the method.

4 The Application object allows you to store data that is scoped at the application level and therefore available to all users.

5 Guidelines that ASP.NET provides automated testing for the following:

Visual Studio can automatically test Web applications for compliance with WCAG Priority 1 guidelines.

Visual Studio can automatically test Web applications for compliance with WCAG Priority 2 guidelines.

Visual Studio automatically tests Web applications for compliance with Section 508 guidelines.

5 Catch unhandled exceptions in an app by:

catch errors at the page level by trapping the Page_Error method.

catch application-wide, unhandled errors by trapping the Application_Error method inside the Global.asax file.

6 View state is the simplest way to store this information. Because it is enabled by default, you might not need to write any code to support state management for your form.

7 Log data to a db when a users session logged out. Respond to the Session_End event. The Session_End event handler is called when a user's session times out. However, this event will not fire in the event of the server being shut off unexpectedly or if the SessionState mode is not set to InProc.

8 Visual Studio provides an editor for the (Expressions) property that enables you to link any other property to a global resource.

9 A master page cannot be a web part but a control could be

10 The IsPostBack property indicates if the client is sending data as part of its request (true) or the page is simply being requested for display (false).

11 You can use the Cache.Insert method to add an object to the cache and specify one or more dependencies, including an expiration time span.

12 Dynamically change master page use the page_PreInit event. Page_PreInit is the last opportunity to change the master page. After this event, the page binds with the master page, preventing you from changing it.

13 The @ MasterType declaration is required to access the properties in the master page.

Content pages must have a MasterPageFile attribute in the @ Page declaration that points to the master page.

14 Themes can be specified in the Page_PreInit event

15. Store a value indicating whether a user is authenticated or not can be stored in session. This prevents the user from hackin with the data.

16 ASP.NET uses the Image.AlternateText parameter to create the alt text for an image. Screen readers typically describe images using the alt text.

DescriptionUrl links to an HTML page that provides a long description of an image. ASP.NET uses this link to create the longdesc HTML attribute.

17 The Flush method sends the current output to the client without ending the response.

18 Server.GetLastError retrieves the most recent error message. After processing it, you call Server.ClearError to remove the error from the queue.

19 The Global.asax file allows you to trap special events such as the Application_Start event.

20 Query strings are stored in the URL. Although they are not the easiest type of client-side state management to implement, they are the only way to enable state management data to be easily bookmarked and e-mailed.

21 The SiteMap class will allow you to load the given site map file and work with the data contained inside.

22 You can make a Cache object expire after a specific time span or at a specific time.

23 PreInit event is where we can store our dynamically generated controls.

24 The SiteMapPath will automatically pick up a site map file and display its contents to a user.

25 Skin files <asp:Label runat="server" BackColor="#FFE0C0" ForeColor="Red"></asp:Label> have not ID attribute

26 Track non confidential info - Client-side state management is an excellent choice for storing nonconfidential information. It is much easier to implement than server-side state management when multiple Web servers are involved, and it minimizes load on the servers.

27 The Page.Server.Transfer method transfers the page processing to another page without calling back to the client.

28 Creating & writing file on serve is indicated by the HTTP verb – PUT..

29 Themes will override attributes directly on a control:
A theme specified using @ Page Theme="MyTomatoTheme"
<pages Theme="themeNameTomato"> element in the Web.config file

30. Retrieve current cookie config settings
HttpCookiesSection section = (HttpCookiesSection)

31 The Response object contains methods such as Response.Cache.SetExpires and Response.AddCacheDependency that enable you to configure page output caching programmatically.

32 Configuring IIS to use worker process isolation mode allows you to create application pools.
33 The Publish dialog box allows you to precompile a Web site. It also allows you to publish from your development server.

34 Windows Authentication: The only step you need to take to enable the user's credentials to be passed to the database server is to enable impersonation

35 To configure the app pool to shut down & restart on a specific time we can add the time to the Recycle Worker Processes At The Following Times list on the Recycling tab of the application pool Properties dialog box to ensure that the process is recycled at a specific time.

36 With an ASP.NET Web Application project you can use the Publish Web dialog box to publish a Web application.

37 We want to rely on ASP.NET dynamic compilation for iterative modifications Create an ASP.NET Web site if you want to rely on ASP.NET dynamic compilation for iterative modifications. The Build command compiles Web site projects only to test them. To run Web sites, you can deploy source files and rely on ASP.NET dynamic compilation to compile pages and classes in the application.

38 Publish Dialog Box: Clear the Allow This Precompiled Site To Be Updatable check box to ensure that pages cannot be updated on the Web server.
39 The ASP.NET Merge tool (Aspnet_merge.exe) enables us to combine and manage assemblies that are created by the ASP.NET Compilation tool (Aspnet_compiler.exe). The ASP.NET Merge tool provides additional flexibility when you precompile the Web site beyond what you can achieve with the ASP.NET Compilation tool alone.

40 We need to configure session state to allow state to be shared across servers. StateServer mode stores session state in a separate process called the ASP.NET State Service. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

SQLServer mode stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

41 Session state stores state management information on the server and tracks a user with a single cookie. Session state is ideal for scenarios such as this because it tracks a user's information for a single visit across multiple Web pages.

42 Given integrated Windows IIS authentication, Windows ASP.NET authentication, and ASP.NET impersonation, ASP.NET will assume the client identity. You must add the accounts of the users requesting the Web page to the database.

43 We must define a membership provider to indicate the membership information store. Designate a membership provider by setting the defaultProvider attribute of the membership element to AspNetSqlProvider.

44 When users access the web app by a browser with cookies disabled. The state mode should be configured as cookieless and using InProc mode.

45 We can easily determine whether a user is in a specific role by calling Roles.IsUserInRole. Alternatively, you can call Roles.GetRolesForUser and iterate through each role to determine user membership.

46 If ASP.NET Windows authentication is configured, we must configure IIS Basic, Digest, or Integrated Windows authentication., We cannot use Integrated Windows authentication if users must authenticate through a firewall.

47 The assembly must be manually copied to the local Bin folder. Referencing from the GAC and configuring Copy Local no longer works in Visual Studio 2008.

48 If we are using a database (SQL Server ), we must run Aspnet_regsql.exe, which is found in %windows%\Microsoft .NET\Framework\<version>. When you run the tool, we specify the -Ap option.

49 With an ASP.NET Web Application project we have complete control of the project's structure, namespaces, and compilation.

50 Digest authentication, as well as Integrated Windows authentication or Basic authentication, support only Windows authentication.

51 Windows authentication can automatically authenticate users to either the Active Directory domain or the local user database. The user's browser can submit the credentials he or she used to log in to his or her computer without prompting the user for a user name and password.

52 The ASP.NET Compilation tool (Aspnet_compiler.exe) enables us to compile an ASP.NET Web application, either in place or for deployment to a target location such as a production server. In-place compilation helps application performance because end users do not encounter a delay on the first request to the application while the application is compiled. We can provide Aspnet_compiler options to prevent the copy of .aspx files.


Let’s continue with some Code

State Management code:


Default Page 2 <br />
<asp:Label ID="LabelApplicationClicks" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="LabelSessionClicks" runat="server" Text="Label"></asp:Label>
<br />
<asp:HyperLink ID="HyperLinkPage1" runat="server" NavigateUrl="~/Default.aspx">HyperLink</asp:HyperLink>


public partial class Default2 : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)
Application["clicks"] = ((int)Application["clicks"]) + 1;
LabelApplicationClicks.Text = "Application clicks: " +
Session["session_clicks"] =
(int)Session["session_clicks"] + 1;
LabelSessionClicks.Text = "Session clicks: "
+ Session["session_clicks"].ToString();

Xml file web.config for users & roles:

<?xml version="1.0" encoding="utf-8"?>
<allow roles="Administrators" />
<deny users="*" />

So we’ve reviewed the Programming Web Applications section & seen some important topics such as appearance, state, layout along with others.

Wow in the 13 posts we covered quite a bit. I think maybe the next posts can be just a random material or more code focused or a summary. We’ll soon find out. Hope your enjoying studying & learning the content like me. What do you think?

That is all there will be more,


No comments: