Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Beginning ASP.NET 2.0 With CSharp (2006) [eng]

.pdf
Скачиваний:
84
Добавлен:
16.08.2013
Размер:
20.33 Mб
Скачать

Chapter 16

Developing is a very proactive job. The idea of a coder sitting in a room and just writing an application from start to finish and delivering it with no contact to the outside world is an outdated one. If your code is being used by thousands of people, you should at least be talking to a fraction of them. If you talk to people, they will undoubtedly have a million ideas you’d never have considered.

References

A lot of a developer’s time will be spent on the web looking up new concepts or error messages. Here’s a list of some good places to start:

http://p2p.wrox.com: The Wrox forums and first place to ask with trouble on the book.

www.developerfusion.co.uk: The UK developer community for ASP.NET.

www.asp.net: The official Microsoft ASP.NET web site.

http://msdn.microsoft.com/asp.net/: The MSDN reference for all things ASP.NETrelated, and an essential reference for any developer.

www.15seconds.com: A great magazine-like site with loads of free articles on ASP.NET 2.0.

http://beta.asp.net: Microsoft’s coverage of the latest version of ASP.NET.

www.dotnet247.com: A compendium, online cross-reference of all the Usenet newsgroups, including all of the ASP.NET 2.0 groups.

http://msdn.microsoft.com/coding4fun/default.aspx: MSDN’s site on fun coding topics.

www.codeproject.com: A good resource for free source code and tutorials.

Summar y

This hasn’t really been a chapter about a particular subject, but rather an extended wrapping up and welcome to the real world. To those ends, this chapter discussed the following:

How you can go about deploying the Wrox United site with both Visual Web Developer and the command-line prompt tool.

The importance of testing your application after it has been deployed and getting your potential users or your customer to test it as well.

Maintenance, and very briefly, ASP.NET 2.0’s new instrumenting feature, the <healthMonitoring> element, and how you might go about using it.

A quick recheck of the Wrox United application and what you learned from it.

Some suggestions about what you should do next after finishing this book.

You’re now ready to start developing without our help.

618

Deployment, Builds, and Finishing Up

Exercise

1.You are now developer and maintainer of the Wrox United web site. What else would you add to the Wrox United site? Make a list of possible add-ons, and prioritize them with the simplest to do first. Implement some of these add-ons. Just to get you thinking, you could add a facility to post pictures or video clips from Wrox United matches, or you could add player biographies. The possibilities are limitless here, so be creative.

619

A

Exercise Answers

Chapter 1

Exercise 1

Explain the differences among the .NET 2.0 Framework, ASP.NET 2.0, VWD, and IIS.

Solution

The .NET 2.0 Framework is a very broad set of code (contained in classes) that is used by many Microsoft products, including servers, database managers, and web servers.

ASP.NET 2.0 is a subset of the .NET 2.0 Framework that holds the classes used to create dynamic web pages.

VWD is a tool used to create ASP.NET 2.0 web pages.

IIS is a web server that can execute the ASP.NET 2.0 code to create dynamic web pages.

Exercise 2

List some differences between ASP.NET Development Server and IIS.

Solution

IIS is a powerful web server designed to support publicly deployed sites. IIS scales to heavy loads, multiple servers, and multi-processor machines. It has a robust security model. The user of IIS is a special account named ASPNET. IIS does not expect pages to be in development while it is serving them, so it does not lock pages.

ASP.NET Development Server is a lightweight web server designed to give developers a quick and easy way to serve a page on their development machine. ASP.NET Development Server cannot handle more than a small number of visitors simultaneously. The user of ASP.NET Development Server is whoever is logged in to Windows at the time, and thus the security model is weak. ASP.NET Development Server locks a page in VWD while it is being served.

Appendix A

Exercise 3

When you drag the title bar of the toolbar it will only go to certain locations and certain sizes. How can you put the title bar where you want it?

Solution

Select the toolbar and choose Menu Windows Floating. You can now place the toolbar in the size and location you desire.

Exercise 4

How can you copy a .jpg file in C:\MyPhotos into your site for display on a page?

Solution

From VWD Solution Explorer, you can right-click the receiving folder and then select Add Existing Item. Navigate to C:\Photos and select the photo of interest. Click OK.

From Windows Explorer, you can copy the .jpg file from its original folder to C:\Website\MyWebName.

Exercise 5

You want to add a subfolder to your site, but folder is not one of the items listed in Add Items. Why?

Solution

Adding a folder has its own entry in the menu that appears when you right-click a folder in the Solution Explorer.

Exercise 6

Microsoft has written extensive code to make it easier for programmers to create web pages. How does a programmer actually use that code?

Solution

The code is available in server-side controls. These are tags that look like HTML but start with <asp: ... >. Within the control you can set properties to determine the appearance and behavior of the control.

Exercise 7

Why are there no tools in the General panel of the Toolbox?

Solution

The General panel is a place for you to place snippets of code that you copy from a page and expect to use again later. It starts out empty.

622

Exercise Answers

Chapter 2

Exercise 1

Describe the functional difference between the Web.config file and Global.asax.

Solution

Web.config contains values (settings), whereas Global.asax contains code.

Exercise 2

What files discussed in this chapter are in XML format?

Solution

Web.config and Site.map.

Exercise 3

Take a look at the code for a Content page. Why does it lack directives and tags?

<!DOCTYPE HTML PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”> <head ></head>

Solution

This code lacks directives and tags because those are supplied by the Master page.

Exercise 4

What values must match between a set of Master and Content pages?

Solution

The Content page’s first line directive of MasterPageFile must match the name of the master file.

The value of xxx in the Content page’s <asp:content ... ContentPlaceHolder ID=”xxx”> must match the ID of the Master page’s <asp:ContentPlaceHolder ID=”xxx”>.

Chapter 3

Exercise 1

Practice using the drag-and-drop functionality of VWD to put together a simple web page that displays the following information:

The WroxUnited Logo (available for free download from www.wrox.com — or just use any small image of your choice).

The names of the players and some information about each of them, arranged in a table. Refer to Figure 3-44 for a visual reference.

623

Appendix A

Solution

The finished page should look like Figure A-1 when it is run.

Figure A-1

The HTML that generates this page will vary according to how you set up your table, but it should be similar to the following code:

<html xmlns=”http://www.w3.org/1999/xhtml” > <head runat=”server”>

<title>Untitled Page</title> </head>

<body>

<form id=”form1” runat=”server”> <img src=”badge.gif” />

<br />

This is my fan site for the Wrox United football team! I’ve met a few of the team - here’s my notes from my meetings:<br />

<br />

<table width=”600” cols=”2”> <tr>

<td style=”width: 150px”> Player</td>

<td style=”width: 400px”> Notes</td>

</tr>

<tr>

<td style=”width: 150px”> Chris Hart</td>

<td style=”width: 400px”>

624

Exercise Answers

Signed my book!</td> </tr>

<tr>

<td style=”width: 150px”> Chris Ullman</td>

<td style=”width: 400px”>

Signed my football!</td> </tr>

</table>

</form>

</body>

</html>

Exercise 2

Return to Wrox United and go to the Master page. Try deleting the Menu control and replacing it with a TreeView control. Bind that control to the siteData data source, and you should see a fully populated tree of items, both in Design View (refer to Figure 3-45) and when you run the page (refer to Figure 3-43).

Solution

Changing the Menu control to a TreeView control is a swift process, and you can see the results in Figure A-2.

Figure A-2

625

Appendix A

After you have a siteMap data source, it’s simple to plug in compatible controls and change the functionality of the site with minimal effort.

Chapter 4

Exercise 1

Change the configuration of your Chapter 4 web site to allow anonymous access, but to deny access to one specific user account.

Solution

Run through the Security wizard for the site and change the permissions as described, or modify the Web.config file. If you are successful, you will have code similar to the following in your Web. config file:

<roleManager enabled=”true” /> <authorization>

<allow users=”?” />

<deny users=”chrishart” /> </authorization>

Exercise 2

Add a subfolder to the Chapter 4 web site called Admin. Within this folder, add a page called MainAdmin.aspx with a LoginName control on it and any other controls you might want. Change the access permissions for that specific folder so that only members of the Administrators group can view the page.

Solution

The MainAdmin.aspx page should have code similar to the following:

<form id=”form1” runat=”server”> <div>

This is the administration page for the Chapter 4 site. <br />

<asp:LoginView ID=”LoginView1” Runat=”server”> <LoggedInTemplate>

You are logged in as <asp:LoginName ID=”LoginName1” Runat=”server” />  <br />

</LoggedInTemplate>

<AnonymousTemplate>

You are currently anonymous. </AnonymousTemplate>

</asp:LoginView>

<asp:LoginStatus ID=”LoginStatus1” Runat=”server” /> </div>

</form>

The Web.config file for the Admin folder should have the following code:

626

Exercise Answers

<?xml version=”1.0” encoding=”utf-8”?> <configuration>

<system.web>

<authorization>

<allow roles=”administrators” /> <deny users=”*” />

</authorization>

</system.web>

</configuration>

Chapter 5

Exercise 1

You have an ASP.NET Label control on a page. The label has a font-italic=”true” attribute, and a

CssClass=”maintext” attribute:

<asp:label id=”myLabel” CssClass=”maintext” font-italic=”true”

text=”This is a label”></asp:label>

The page has an associated CSS style sheet (not associated with a theme) that defines a .maintext style class has the following attributes:

.maintext

{

color: Navy; font-family: Verdana; font-weight: Bold; font-style: normal;

}

How will the label appear when it is rendered?

Solution

You should see some text rendered in bold, blue Verdana, and italic, as shown in Figure A-3.

Figure A-3

627