Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Build Your Own ASP.NET 2.0 Web Site Using CSharp And VB (2006) [eng]-1.pdf
Скачиваний:
142
Добавлен:
16.08.2013
Размер:
15.69 Mб
Скачать

Chapter 5: Building Web Applications

Figure 5.32. The cookie has persisted

If you reload the page, the cookie will be found, and you’ll get a different message, as Figure 5.32 shows.

If you go through the code, you’ll see that it’s pretty much self-explanatory. What’s interesting to observe is that you can close the browser window, or even restart your computer—the cookie will still be there, and the application will be able to identify that you’re a returning visitor. As you can see in the code, the cookie is set to expire one month after creation.

Be aware that visitors can choose to reject your cookies, so you can’t rely on them for essential features of your application.

Starting the Dorknozzle Project

You’re now prepared to start developing a larger project! We were introduced to Dorknozzle at the beginning of the chapter, and you’ve already created a project for it. Now, it’s time to add some real functionality to it! In the next few pages, we will:

Prepare the sitemap for your site.

Create a default theme that defines the common styles.

Create a master page that will contain the layout for all the pages of Dorknozzle.

Create a web form that uses the master page.

Learn how to debug your project in case you encounter errors.

186

Preparing the Sitemap

The star of the show will be the master page, but because it needs to have the sitemap and the theme in place, we’ll deal with these first.

Preparing the Sitemap

As we saw in Figure 5.1, on the left of every page of our Dorknozzle site will sit a menu that contains links to the site’s pages. We’ll implement that list using the SiteMapPath control, which will require a sitemap file.

Adding Files to your Project

If the project is running in debug mode, you can’t add new files to it, so you must first stop debugging. You can do this by closing the browser window (if you’re using Internet Explorer), by selecting Debug > Stop Debugging, or by clicking the Stop icon on the debug toolbar.

In Solution Explorer, right-click the root node and select Add New Item, as illustrated in Figure 5.33.

Figure 5.33. Adding a new item to your project

187

Chapter 5: Building Web Applications

Figure 5.34. Adding a sitemap file

From the templates list, choose Site Map, as depicted in Figure 5.34 and leave the filename as Web.sitemap.

Click Add to have the file created and added to your project. You’ll be presented with a default, empty sitemap that you can start modifying. Change its contents as shown below. For now, you need only add a few nodes; you can add the rest later on.

File: Web.sitemap

<?xml version="1.0" encoding="utf-8" ?> <siteMap

xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="~/" title="Root" description="Root">

<siteMapNode url="~/Default.aspx" title="Home" description="Dorknozzle Home" />

<siteMapNode url="HelpDesk.aspx" title="Help Desk" description="Dorknozzle Help Desk" />

<siteMapNode url="~/EmployeeDirectory.aspx" title="Employee Directory" description="Dorknozzle Employee Directory" />

<siteMapNode url="~/AddressBook.aspx" title="Address Book" description="Dorknozzle Address Book" />

188