1. Trang chủ
  2. » Công Nghệ Thông Tin

Beginning ASP.NET 1.1 with Visual C# .NET 2003 phần 10 pps

81 294 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Beginning ASP.NET 1.1 with Visual C# .NET 2003 phần 10 pps
Chuyên ngành Web Application Development
Thể loại Dự án tốt nghiệp
Định dạng
Số trang 81
Dung lượng 2,55 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

After running this, my code was spaced out a bit better, and my preferred capitalization ruleswere followed as can be seen in Figure D-40: 783 Web Application Development Using Visual St

Trang 1

Figure D-38

Formatting Blocks of Code

I often find Visual Studio NET a bit messy at times – after adding this table, you can see that the codegenerated on my system was hardly tidy In my default preferences (you can specify your own

preferences via Tools | Optionsfrom the main menu) I specified that I wanted all tags to be in lowercasewhen editing HTML code, and I wanted to use two spaces indentation for all lines of code, yet the editoradded the code shown in Figure D-39:

782

Appendix D

Trang 2

Figure D-39

The solution to this problem is to select all the code and use the Edit | Advanced | Format Documentmenuoption After running this, my code was spaced out a bit better, and my preferred capitalization ruleswere followed as can be seen in Figure D-40:

783

Web Application Development Using Visual Studio NET

Trang 3

Figure D-40

You will find that the results of this will vary according to the default preferences you have on yoursystem, but once you have set up the defaults as you like them, you'll find that this feature can be veryhandy!

Developing the User Control

In this table, set the row and cell attributes as shown in the code below Leave the last cell empty for themoment:

<tr style="VERTICAL-ALIGN: middle">

<td style="TEXT-ALIGN: left" width="200">

<a href="default.aspx"><img src="images/logo.gif" border="0" /></a>

Trang 4

Web Application Development Using Visual Studio NET

Trang 7

Back in the header.ascxfile, head to the Propertiesfor the advertisement file again Select the

AdvertisementFileattribute and click on the button that appears In the popup dialog shown inFigure D-44, select the Faces.xmlfile and click OK:

Trang 8

Finally, right-click on Header.ascxand select View Code You are now in the code-behind page for theheader control Add the following line of code directly above the Page_Loadsub, as shown in Figure D-45:

public string PageTitle = "";

Figure D-45

Time for a quick File| Save Alland that's the control done! Time to add it to the page!

Adding a User Control to a Page

Switch to the Designview for Default.aspx Click and drag Header.ascxfrom the Solution Exploreronto the page, right before the main header This is shown in Figure D-46:

789

Web Application Development Using Visual Studio NET

Trang 9

Figure D-46

You'll notice that this will add the control its reference to the HTML of the page Also, notice that thecontrol appears as a gray box, with no design-time appearance (Web Matrix, you will recall, provided asample of the appearance of each user control as it was added to a page)

The newly added control is added with a default TagNameof Headerand TagPrefixof UC1 You canchange this prefix to WroxUnited(if you prefer) by editing the HTML of the page Since we need to tidy

up this page in any case, let's do that now Amend the highlighted lines of code (notice that you need toremove the <h1>tag and the default header text):

<%@ Register TagPrefix="WroxUnited" TagName="Header" Src="Header.ascx" %>

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Default.aspx.vb" debug="true" Inherits="WroxUnited.WebForm1"%>

<body>

<form id="Form1" method="post" runat="server">

<WroxUnited:header id="Header1" runat="server">

</WroxUnited:header>

790

Appendix D

Trang 10

<table id="Table1" cellspacing="0" cellpadding="0" width="800"

Adding Custom Classes

It's time to look at adding a data access component Right-click on the WroxUnitedproject and selectAdd New Item In the dialog shown in Figure D-48, select the Classtemplate, and name the fileDataAccessCode.cs

Figure D-48

791

Web Application Development Using Visual Studio NET

Trang 11

In the code, add some usingstatements at the top of the code:

792

Appendix D

Trang 12

Figure D-50

Add the following line of code directly above the Page_Loadmethod:

public DataAccessCode Data = new DataAccessCode();

Then prefix each underlined method with "Data." The code should now be able to locate the methods

in question Notice that as you do this, IntelliSense locates the list of available methods in this class andgives you hints about what their signatures look like This is shown in Figure D-51:

793

Web Application Development Using Visual Studio NET

Trang 13

Figure D-51

Complete adding each method call with the Dataobject prefix, and you will be able to run the page,which should look and feel the same as before

You can duplicate this methodology to create custom server controls in exactly the same way

Professional and higher editions of Visual Studio NET allow you to create entire custom class libraryprojects and custom server control projects, but this functionality isn't available in the Standardlanguage-specific editions

Working with Databases Using the Server

Explorer

If you click the Server Explorertab (at the bottom of the Toolbox), you can see the database connectivityfunctionality of Visual Studio NET By default, this will look at little empty Click on the Connect toDatabasebutton to add a new connection, as shown in Figure D-52:

794

Appendix D

Trang 16

In Standard edition, you can edit the data contained in the table, but cannot edit the structure of anexisting table or create a new table However, you can enter SQL as shown in Figure D-55, and if youknow how to write SQL, you can enter any valid SQL statement, including CREATE TABLE, DROP TABLE,

or even CREATE DATABASEstatements:

Figure D-55

If you are using Professional or higher editions of Visual Studio NET, you can simply right-click on atable and create a new table, or alter the design of a table using the context menu You can also createstored procedures and views in this way

Debugging in Visual Studio NET

One of the most powerful and indispensable features of Visual Studio NET is its ability to debug codeand fix errors First, we'll look at break points and stepping through code line-by-line at run-time to fixrun-time errors or exceptions, then we'll look at fixing errors at compile time

797

Web Application Development Using Visual Studio NET

Trang 17

Using Breakpoints

In Default.aspx.cs(the code-behind for the web page), click in the margin next to one of the lines ofcode, for example, the first line of code in the event-handler for the clicking of the button on the pageshown in Figure D-56:

Figure D-56

This has added a breakpoint to the code, which means that when that line of code is processed, you canstep inside and see what's happening To demonstrate this, run the page – notice that when you click thebutton on the page, you automatically switch back to the screen shown in Figure D-57:

You can only debug if the compilation mode of your solution is set to Debug (see the drop down box next to the Runbutton on the main toolbar) Once you finish

debugging and are ready to deploy your site, set this to Release– you'll notice a

significant performance boost on higher-traffic sites because debug code is much

more processor intensive If you're not debugging, turn it off!

798

Appendix D

Trang 18

Figure D-57

At the bottom left of the screen, you can see the value entered into the textbox when the button wasclicked You can watch the values of controls on the page using this window You can step through thiscode line by line to see what happens when each line of code is run by pressing F11 When you reach amethod call, you can either press F11to jump into the code where that method is defined and watch as

the code in that method is executed line by line (Step Into), or you can press F10 to Step Over this method

and continue with the next line of code in the current code block

Pressing the Startbutton again will continue execution of the page, taking you back to the browserwindow, as if no interruption had occurred This feature is particularly useful when fixing broken code.All you have to do is add a break point before the piece of code that is broken and step into the code,watching to see where the code breaks This will often give you a clear idea as to why the code is notrunning as expected

Fixing Design-Time Errors

You will often find that errors at design time will prevent a page from compiling correctly For example,

if you forgot to prefix one of the methods on the page with the Data.object reference, you would see anerror message when you tried to run the page, as shown in Figure D-58:

799

Web Application Development Using Visual Studio NET

Trang 20

Figure D-59

It's now fairly obvious that the compiler can't deduce where the AddNewFanEmailmethod is declared,but once you add the Data., prefix, it'll soon find what it's looking for

Suggested Exercises and Further Reading

After completing this appendix, you will probably feel a bit more confident with creating web

applications in Visual Studio NET The best way to increase your confidence further is to try out addingmore controls and pages yourself You may want to try to implement the whole of the Wrox Unitedapplication in Visual Studio NET – this would give you experience of working with many differentcontrols in the Visual Studio NET environment, as well as programming with many different ASP.NETtechniques

Visual Studio NET is a large product, so if you really want to learn more about this tool, visit

http://msdn.microsoft.com/vstudio/using/

801

Web Application Development Using Visual Studio NET

Trang 22

of the dialog boxes.

Before you install it though, it's worth noting that you might not have to do much in this initialstage, as it's possible you're already running IIS We'll describe a process for checking whether this

is the case as part of the installation process Note that to install anything (not just ASP.NET, but

literally anything) on Windows 2000, XP, and 2003 you need to be logged in as a user with

administrative rights If you're uncertain about doing this, please consult your Windows

documentation Right, let's get started!

Try It Out Creating a Virtual Directory and Setting Up Permissions

1. Go to the control panel (Start | Settings | Control Panel) and select the Add/Remove Programsicon The dialog will appear, displaying a list of your currently installed programs asshown in Figure E-1:

You cannot install IIS on Windows XP Home Edition It will only work on Windows

XP Professional.

Trang 23

Appendix E

Trang 24

4. If the checkbox is unchecked, check it and click Nexton the screen shown in Figure E-2 to loadInternet Information Services You might be prompted to place your Windows 2000 or XP

installation disk into your CD-ROM drive It will take a few minutes to complete Then go toStep 5

OR

If the checkbox is checked, you won't need to install the IIS component – it's already present on

your machine Go to the Working With IIS section instead.

5. Click on the Detailsbutton – this will take you to the dialog shown in Figure E-3

Figure E-3

6. There are a few options here for the installation of various optional bits of functionality Forexample, if the World Wide Web Serveroption is checked then your IIS installation will be able toserve and manage Web pages and applications If you're planning to use FrontPage 2000 orVisual Studio.NET to write your Web page code, then you'll need to ensure that the FrontPage

2000 Server Extensionscheckbox is checked The Internet Information Services Snap-Inis also veryhelpful, as you'll see later in the chapter, so ensure that this is checked too; the other options(although checked here) aren't necessary for this book:

How It Works

IIS starts up automatically as soon as its installation is complete, and thereafter whenever you boot upWindows Thus you don't need to run any startup programs or click on any short cuts

IIS installs most of its components on your hard drive, under the \WinNT\system32\inetsrv

directory; however, we are more interested in the \InetPubdirectory that is also created at this time.This directory contains subdirectories that will provide the home for the Web page files that we create

If you expand the InetPubdirectory, you'll find that it contains several subdirectories:

❑ \iissamples\homepagecontains some examples of classic ASP pages

805

Installing and Configuring IIS

Trang 25

❑ \iissamples\sdkcontains a set of subdirectories that hold classic ASP pages which

demonstrate the various classic ASP objects and components

❑ \scriptsis an empty directory, where ASP.NET programs can be stored

❑ \webpubis also empty This is a special virtual directory, used for publishing files via the Publishwizard Note that this directory only exists if you are using Windows 2000 Professional Edition

❑ \wwwrootis the top of the tree for your Web site This should be your default Web directory Italso contains a number of subdirectories that contain various bits and pieces of IIS This

directory is generally used to contain subdirectories that hold the pages that make up our Website – although, in fact, there's no reason why you can't store your pages elsewhere The

relationship between physical and virtual directories is discussed later in this appendix

❑ \ftproot, \mailrootand \nntprootshould form the top of the tree for any sites that useFTP, mail or news services, if installed

❑ In some versions of Windows, you will find a \AdminScriptsfolder that contains variousscript files for performing some common 'housekeeping' tasks on the Web server, allowing you

to stop and start services

Working with IIS

Having installed IIS Web server software, you'll need some means of administering its contents andsettings In this section, we see the user interface that is provided by IIS

In fact, some versions of IIS provide two user interfaces, the Microsoft Management Console (MMC) and the Personal Web Server (PWS) interface (which is just included for those people familiar with PWS from

Windows 98 and looking to migrate to IIS) Let's look at MMC, as the other interface is now obsolete The Microsoft Management Console (MMC)

The best part of MMC is that it provides a central interface for administrating all sorts of services thatare installed on your machine We can use it to administer IIS In fact, when we use it to administer otherservices, the interface looks roughly the same The MMC is provided as part of the Windows 2000operating system – in fact, the MMC also comes with older Windows server operating systems

The MMC itself is just a shell – on its own, it doesn't do much at all If you want to use it to administer a

service, you have to add a snap-in for that service The good news is that IIS has its own snap-in.

Whenever you need to administer IIS, simply call up the Internet Services Manager MMC console byselecting Start | Control Panel | Administrative Tools | Internet Services Manager:

Figure E-4

806

Appendix E

Trang 26

Having opened the IIS snap-in within the MMC, you can perform all of your Web management tasksfrom this window as seen in Figure E-4 The properties of the Web site are accessible via the Default WebSitenode We'll be using the MMC more a little later in the chapter.

Testing Your Installation

The next thing to do is test the Web server to see if it is working correctly, and serving pages as it should

be We've already mentioned that the Web services should start as soon as IIS has been installed, and willrestart every time you start your machine In this section, we'll try that out

In order to test the Web server, we'll start up a browser and try to view some Web pages that you knoware already placed on the Web server In order to do that, you need to type a URL (Uniform ResourceLocator) into the browser's Addressbox, as you often do when browsing on the Internet

What URL do you use in order to browse to your Web server? If your Web server and Web browser areconnected by a local area network, or if you're using a single machine for the Web server and thebrowser, then it should be enough to specify the name of the Web server machine in the URL

Identifying Your Web Server's Name

By default, IIS will take the name of your Web server from the name of the computer You can changethis in the machine's network settings If you haven't set one, then Windows will generate one

automatically – note that this automatic name won't be terribly friendly; probably something along thelines of P77RTQ7881 To find the name of your own Web server machine, select Start | Settings | Networkand Dial-up Connectionsor Start | Settings | Control Panel | System(depending on which operating systemyou are using – if it isn't in one, try the other) and from the Advancedmenu select Network Identification.This tab will display your machine name under the description Full computer nameas shown in Figure E-5:

Figure E-5

807

Installing and Configuring IIS

Trang 27

My machine has the name chrisuhome, and (as you can see here and in Figure E-4) my Web server hasadopted the same name On a computer within a domain, for example a WROX_UKdomain, it would belike WROX_UK/chrisuhome However, this doesn't alter operation for ASP.NET Browsing to pages on thismachine across a local area network (or even from the same machine), I can use a URL that beginshttp://chrisuhome/…

There are a couple of alternatives if you're using the same machine as both Web server and browser Tryhttp://127.0.0.1/… Here, 127.0.0.1is a default that causes requests to be sent to a Web server on the localmachine Alternatively, try http://localhost/… where localhostis an alias for the 127.0.0.1address You mayneed to check the LAN settings (in your browser's options) to ensure that local browsing is not through aproxy server (a separate machine that filters all incoming and outgoing Web traffic employed at mostworkplaces, but not something that affects you if you are working from home)

Managing Directories on Your Web Server

Before installing ASP.NET, you need to make one last pit stop in IIS This is because when you run yourASP.NET pages, you need to understand where to place your pages, and how to make sure you have thepermission to access them As this is governed by IIS, let's look at it now

These days, many browsers are sufficiently advanced that you can use them to locate and examine filesand pages that exist on your computer's hard disk For example, you can start up your browser, type inthe physical location of a Web page (or other file) such as C:\My Documents\mywebpage.html, and thebrowser will display it However, this isn't real Web publishing at all

First, Web pages are transported using HTTP protocol Note that the http://at the beginning of a URLindicates that the request is being sent by HTTP Requesting C:\My Documents\mywebpage.htmlinyour browser doesn't use HTTP, and this means that the file is not delivered and handled in the way a

Web page should be No server processing is done in this case HTTP is discussed in Chapter 2.

Second, consider the addressing situation The C:\My Documents\mywebpage.htmlstring tells us thatthe page exists in the \My Documentsdirectory of the C:drive of the hard disk of the machine on whichthe browser is running In a network situation, with two or more computers, this simply doesn't giveenough information about the Web server

However, when a user browses (via HTTP) to a Web page on some Web server, the Web server will need

to work out where the file for that page is located on the server's hard disk In fact, there's an importantrelationship between the information given in the URL, and the physical location (within the Webserver's file system) of the file that contains the source for the page

Throughout the book, in any examples that require you to specify a Web server

name, the server name will be shown as localhost, implicitly assuming that your Web server and browser are being run on the same machine If they reside on different

machines, then you simply need to substitute the computer name of the appropriate

Web server machine.

808

Appendix E

Trang 28

Virtual Directories

So how does the relationship between the information given in the URL, and physical location work? Itworks by creating a second directory structure on the Web server machine, which reflects the structure

of your Web site

The first directory structure is what you see when you open Windows Explorer on the Web server –

these directories are known as physical directories For example, the C:\My Documentsfolder is a physical directory

The second directory structure is the one that reflects the structure of the Web site This consists of a

hierarchy of virtual directories We use the Web server to create virtual directories, and to set the

relationship between the virtual directories and the real (physical) directories

When you try to visualize a virtual directory, it's probably best not to think of it as a directory at all.Instead, just think of it as a nickname or alias for a physical directory that exists on the Web servermachine The idea is that when a user browses to a Web page that is contained in a physical directory onthe server, they don't use the name of the physical directory to get there Iinstead, they use the physicaldirectory's nickname

To see how this might be useful, consider a Web site that publishes news about different sporting events

In order to organize his Web files carefully, the Webmaster has built a physical directory structure on hishard disk, which looks like Figure E-6:

Figure E-6

Now, suppose you visit this Web site to get the latest news on the javelin event in the Olympics If theURL for this Web page were based on the physical directory structure, the URL for this page would besomething like this:

http://www.oursportsite.com/sportsnews/athletics/field/javelin/default.asp

That's okay for the Webmaster, who understands his directory structure; however it's a fairly

unmemorable Web address! So, to make it easier for the user, the Webmaster can assign a virtual

directory name or alias to this directory – it acts just like a nickname for the directory Here, let's supposewe've assigned the virtual name javelinnewsto the C:\inetpub\ \javelin\directory Now, theURL for the latest javelin news is:

http://www.oursportsite.com/javelinnews/default.asp

809

Installing and Configuring IIS

Trang 29

By creating virtual directory names for all the directories (such as baseballnews, 100mnews, 200mnews,and so on) it's easy for the user to type in the URL and go directly to the page they want:

performance-wise to have too many virtual directories

Let's have a crack at setting up our own virtual directories and permissions (please note that thesepermissions are set automatically if you use the FrontPage editor to create a new site – so don't useFrontPage to set up this site for you unless you know what you're doing)

Try It Out Creating a Virtual Directory and Setting Up Permissions

It's time to create our own virtual directory We'll use this directory to store the examples that we'll becreating in this book We don't want to over complicate this example by creating lots of directories, sowe'll demonstrate this by creating a single physical directory on the Web server's hard disk, and usingthe IIS admin tool to create a virtual directory and make the relationship between the two:

1. Start Windows Explorer and create a new physical directory named BegASPNET11, in the rootdirectory of your hard drive For example, C:\BegASPNET11as shown in Figure E-7:

810

Appendix E

Trang 30

Figure E-7

2. Next, start up the IIS admin tool (using the MMC, as described earlier) Right-click on DefaultWeb Site, and from the menu that appears select New | Virtual Directory This starts the VirtualDirectory Creation Wizard, which handles the creation of virtual directories for you and thesetting up of permissions as well You'll see the splash screen first as shown in Figure E-8 Click

Trang 31

Figure E-9

4. As shown in Figure E-10, click on the Browsebutton and select the directory C:\BegASPNET11that you created in Step 1 Then click Next:

Figure E-10

5. Make sure that the Readand Run scriptscheckboxes are checked, and that the Executecheckbox

is empty Click on Nextin Figure E-11, and in the subsequent page click on Finish:

Figure E-11

812

Appendix E

Trang 32

6. The BegASPNET11virtual directory will appear on the tree in the IIS admin window as shown

You've also created a virtual directory called BegASPNET11as an alias for the physical BegASPNET11

directory If while creating Chapter 1 examples you place the ASP.NET files in the physical

C:\BegASPNET11\ch01directory, you can use the browser to access pages stored in this folder You'llneed to use the URLhttp://my_server_name/BegASPNET11/ch01/…

Also you note that the URL uses the alias /BegASPNET11; IIS knows that this stands for the directorypath C:\BegASPNET11 When executing ASP.NET pages, you can reduce the amount of typing you need

to do in the URL, by using virtual directory names in your URL in place of the physical directory names

We also set the permissions read and run – these must be set or the IIS security features will prevent youfrom running any ASP.NET pages The Executecheckbox is left unselected as allowing others to runapplications on your own machine is a sure way of getting viruses or getting hacked We'll take a closerlook at permissions now, as they are very important If you don't assign them correctly you may findthat you're unable to run any ASP.NET pages at all Worse still, anybody can access your machine, andalter (even delete) your files via the Web

813

Installing and Configuring IIS

Trang 33

As you've just seen, we can assign permissions to a new directory as you create it, by using the optionsoffered in the Virtual DirectoryWizard Alternatively, you can set permissions at any time, from the IISadmin tool in the MMC To do this, right-click on the BegASPNET11virtual directory in the IIS admintool, and select Properties You'll get the dialog shown in Figure E-13:

Figure E-13

Access Permissions

The four checkboxes on the left (see Figure E-13) govern the types of access for the given directory anddictate the permissions allowed on the files contained within that directory Let's have a look at whateach of these options means:

page It's only possible to allow this permission if the Reador Writepermission has already beenassigned But we generally don't want our users to be able to view our ASP.NET source code, so

we would usually leave this checkbox unchecked for any directory that contains ASP.NETpages By default, all directories created during setup have Script Source Accesspermissiondisabled You should leave this as is

Read: This permission enables browsers to read or download files stored in a home directory or

a virtual directory If the browser requests a file from a directory that doesn't have the Readpermission enabled, then the Web server will simply return an error message Note that whenthe folder has Readpermission turned off, HTML files within the folder cannot be read;

however, ASP.NET code within the folder can still be run Generally, directories containinginformation that you want to publish (such as HTML files, for example) should have the Readpermission enabled, as we did in our earlier example

814

Appendix E

Trang 34

Write: If the write permission on a virtual directory is enabled, then users will be able to create

or modify files within the directory, and change the properties of these files This is not normallyturned on, for reasons of security and we don't recommend you alter it

see a list of all the files that are contained in that directory), check the Directory Browsingoption

If someone tries to browse the contents of a directory that has Directory Browsingenabled but Readdisabled, then they will receive the message seen in Figure E-14:

Figure E-14

Execute Permissions

There's a dropdown list box near the foot of the Propertiesdialog, labeled Execute permissions– thisspecifies what level of program execution is permitted on pages contained in this directory There arethree possible values here – None, Scripts only, or Scripts and Executables:

❑ Setting Executepermissions to Nonemeans that users can only access static files, such as imagefiles and HTML files Any script-based files of other executables contained in this directory areinaccessible to users If you tried to run an ASP.NET page, from a folder with the permission set

For security reasons, we recommend disabling this option unless your users

specifically need it – such as when transferring files using FTP (file transfer

protocol), from your Web site

815

Installing and Configuring IIS

Trang 35

to None, you would get the following – note the Execute Access Forbiddenmessage in the pageshown in Figure E-15:

Figure E-15

❑ Setting Executepermissions to Scripts Onlymeans that users can also access any script-basedpages, such as ASP.NET pages So if the user requests an ASP.NET page that's contained in thisdirectory, the Web server will allow the ASP.NET code to be executed, and the resulting HTML

to be sent to the browser

❑ Setting Executepermissions to Scripts and Executablesmeans that users can execute any type offile type that's contained in the directory It's generally a good idea to avoid using this setting, inorder to prohibit users from executing potentially damaging applications on your Web server.For any directory containing ASP.NET files that you're publishing, the appropriate setting for theExecutepermissions is Scripts Only There is one last bit about directory that needs pointing out thoughfor users of Windows 2000

Configuring Directory Security in Windows 2000

If you're running Windows 2000 Server, you might have one extra bit of configuration to do In ASP.NETall ASPX pages run under a special user account named ASPNET For security reasons this account hasrestricted permissions by default; ordinarily, this isn't a problem The database samples in this chapteruse Access When updating data in a database Access creates a separate file (with a ldbsuffix), whichholds the locking information These are the details that stores who is updating records, and the lockingfile is created and removed on demand

The security problem encountered is that we are running pages under the ASPNET account, whichdoesn't have write permissions in the samples directory Consequently, any ASP.NET pages that update

a sample Access mdbdatabase will fail Setting the write permission is simple – just follow these steps:

816

Appendix E

Trang 36

1. In Windows Explorer, select the BegASPNET11directory, where the samples are located.

2. Using the right mouse button, select the Propertiesmenu option, and from the Propertiesdialogthat appears, select the Securitytab as shown in Figure E-16:

Figure E-16

3. Click the Addbutton to display the Select Users or Groupsdialog In the blank space enterASPNETand click the Check Namesbutton This checks the name you've entered and adds themachine name to it:

Trang 37

Writepermission and tick it This gives the ASPNETuser write permission to the BegASPNet11directory tree:

Figure E-18

5. Click the OKbutton to save the changes, and to close the dialog

The security issue arises only if you need write access to a directory, in the same manner as required byour examples (which use Access) Most production Web sites wouldn't use Access as their databasestore, since Access isn't designed for a high number of users In these cases SQL Server would be a morelikely choice The NET SDK documentation has examples of connection strings for SQL Server

Browsing to a Page on Your Web Server

You can test the installation by viewing some classic ASP pages hosted on your Web server, by browsing

to them with your Web browser Let's test out this theory by viewing our default home page, which ishttp://localhostand should appear something like Figure E-19 (this was taken on Windows XP

Professional, so it might appear a little differently):

818

Appendix E

Trang 38

Figure E-19

If you see the screen as shown in Figure E-19, it means the install has worked and you can jump back to

Chapter 1 and the section on creating your first ASP.NET page.

What Do You Do if This Doesn't Work?

If it's not working correctly, then you are most likely to be greeted with the screen similar to Figure E-20:

819

Installing and Configuring IIS

Trang 39

Figure E-20

If you get this page, it can mean a lot of things; however, one of the most likely problems is that yourWeb services under IIS are not switched on To switch on Web services, you'll first need to start the IISadmin snap-in that we described earlier in the chapter (select Start | Run, type MMCand hit OK; thenselect Openfrom the MMC's Consolemenu and locate the iis.mscfile from the dialog Alternatively,just use the shortcut that you created there)

Now, click on the +of the root node in the left pane of the snap-in, to reveal the Defaultsites Then click on Default Web Site, and select Startas shown in Figure E-21:

right-820

Appendix E

Trang 40

Figure E-21

If it's still not working then here are a few more suggestions, which are based on particular aspects ofyour PC's setup If you're running on a network and using a proxy server (a piece of software thatmanages connections from inside a firewall to the outside world – don't worry if you don't have one,they're mainly used by big businesses), there's a possibility that this can prevent your browser fromaccessing your Web server Most browsers will give you an opportunity to bypass the proxy server

❑ If you're using Internet Explorer, you need to go to View | Internet Options(IE4) or Tools | InternetOptions(IE5/IE6) and select the Connectionstab In IE5/IE6 press the LAN Settingsbutton andselect Bypass the proxy server for local addresses In IE6, this section forms part of the

Connectionsdialog and can be accessed by pressing the LAN settings dialog as shown in FigureE-22:

Figure E-22

821

Installing and Configuring IIS

Ngày đăng: 13/08/2014, 04:21

TỪ KHÓA LIÊN QUAN