Beginning asp net 2.0 with c phần 10 pot

76 260 0
Beginning asp net 2.0 with c phần 10 pot

Đ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

Setup Click OK You are returned to the Wrox United Properties dialog box This time, select the new NETWORK SERVICE option Scroll down and check the box next to Write (see Figure B-22) Click Apply, and then click OK Figure B-22 This will enable your account to access the database Windows XP Home Edition Users Only If, when you come to browse for a Security tab in Windows Explorer, you can’t find one, this is because you have Windows XP Home Edition installed and you have a slightly more complex route to enable the correct permissions Apparently, Windows XP Home Edition users just aren’t allowed to have the same kind of power as their XP Professional counterparts To get around this, restart your computer in Safe Mode To this, restart your machine, and before the Windows XP logo appears, hold down the F8 key and select Safe Mode Let XP continue and then log in as Administrator You’ll receive a warning about running in Safe Mode, but click Yes anyway Locate the C:\WebSites\WroxUnited folder in Windows Explorer and right-click the App_Data folder Select Properties and select the Security tab that has now appeared Now go back to step in the previous section and follow the instructions from there on At the end, though, shut down and restart your machine in normal mode before you continue to the next step Checking the Installation with VWD and the ASP.NET Development Server After you have successfully downloaded the Wrox United zip file, unzipped it, and enabled the Network Service, you are ready to check your installation Follow these steps: 661 Appendix B Select the Start menu and navigate to All Programs Select the Visual Web Developer 2005 Express Edition Icon at the bottom of the menu VWD will open Select File➪Open Web Site, and browse to C:\Websites\WroxUnited and click Open When the web site has loaded into Solution Explorer, double-click default.aspx to open the file Press the F5 key to run the page and observe it in a browser You should see what appears in Figure B-23 in your browser Figure B-23 Checking the Installation with IIS Follow this step only if you have installed IIS and intend to use it as your main web server To open WroxUnited with IIS, start Internet Explorer and type http://localhost/WroxUnited into the Address line The web site should start and display what’s shown in Figure B-24 Please note that while Figure B-22 is seemingly identical to Figure B-21, the Address line reveals a small difference If you are running your site on ASP.NET Development Server (the free web server with VWD), you will get the following line (potentially with a different number): http://localhost:1231/WroxUnited This indicates that the web server is running on port 1231 The ASP.NET Development Server will arbitrarily assign a port number in the URL If you are running the web site on IIS, then you see the following line: http://localhost/WroxUnited 662 Setup Figure B-24 IIS by default runs on port 80, and this doesn’t need to be specified in the URL Occasionally, if port 80 is taken by another process, IIS will default to http://localhost:8080, or you might have to specify it yourself if you get an error message saying Unexpected error 0x8ffe2740 occurred This means that another application is using port 80 To alter this, you need to start the IIS manager from Administrative Tools in the Control Panel, right-click the Default Web site in the left panel, and select Properties From the Web Site tab, change the number there from 80 to 8080, or if 8080 is taken then 8081, or the first one free above that number Troubleshooting By and large, installation with SQL Express and the ASP.NET development is straightforward However, if you are trying to use SQL Server 2005 rather than SQL Express, you should run through the following extra steps: Add [machine\ASPNET] and [NT AUTHORITY\NETWORK SERVICE] as logins, substituting machine with your machine name Attach the database (wroxunited.mdf), making ASPNET the db_owner Add [machine\ASPNET] and [NT AUTHORITY\NETWORK SERVICE] as database users Change the connection strings in web.config That should be all for the WroxUnited database Then there’s the providers, which can be added to either the WroxUnited database or to a separate one 663 Appendix B Run aspnet_regsql (in the framework directory), to add user/roles/etc tables/procs to the appropriate database Add provider sections in web.config, for , , and , setting the default provider for each to the new provider added These providers should point at the ConnectionString for the database (which will be either WroxUnited or a new connection string if you’re using another database) Note that if you are using a different version of SQL Server than 2005, it isn’t possible to just attach the database to the different version If you are using the full version of 2005 and you encounter the following problem: Server Error in ‘/WroxUnited’ Application Failed to generate a user instance of SQL Server due to a failure in copying database files The connection will be closed Description: An unhandled exception occurred during the execution of the current web request Please review the stack trace for more information about the error and where it originated in the code Exception Details: System.Data.SqlClient.SqlException: Failed to generate a user instance of SQL Server due to a failure in copying database files The connection will be closed you will need to the following: Reboot windows Log in as Administrator (if you aren’t running with Admin privileges) Delete the C:\Documents and Settings\username\Local Settings\Application Data\ Microsoft\Microsoft SQL Server Data\SQLEXPRESS directory You might need to logout and log back in as a “normal” user if you normally run with non-admin privileges If this doesn’t work, try the following solution — there is a known problem with remote logging on and SQL Express, which the following steps should circumvent: Go to the SQL Configuration Manager Right-click SQL Express and select Properties From the Logon tab, change the account from Network Service to Local System Try to run it again Apart from that, if you encounter a problem go to http://forums.asp.net or http://p2p.wrox.com and check to see if your problem is addressed there 664 C Wrox United Database Design Throughout this book, you’ve seen examples based on the fictional Wrox United soccer team web site The application relies on a SQL Server database, supplied with the code downloads for this book (available at www.wrox.com) This database stores details of the players in the team, fixtures and results, news items, orders from the shop, and so on This appendix is not intended to provide a thorough overview of database design principles, and as such, we recommend that you read Wrox’s Beginning Database Design The database schema looks like Figure C-1 Figure C-1 Appendix C This diagram illustrates the tables that exist within the database, and the relationships between those tables For example, players score goals, goals are scored at fixtures, match reports are written about specific fixtures, and so on Many tables relate to other tables in the database, but there are some tables that stand on their own; for example, the News table, which stores news articles This table doesn’t link to data stored in any other table Notice also that the Orders, Products, and OrderLines tables are separate from the rest of the database — these tables are used to store data relating to orders from the Wrox United shop This appendix walks through the structure of each of the tables in the database and describes the relationships between them Players and Matches The players on the Wrox United team are involved in many fixtures, and several related tables in the database store related data for matches Take a look at these tables first The Players Table The following shows the structure of the Players table Field Data Type Allow Nulls PlayerID (Primary Key) int No FirstName varchar(25) No LastName varchar(25) No Position varchar(50) Yes PictureURL varchar(255) Yes DateJoined datetime Yes DateLeft datetime Yes This table is typical of all database tables in that it has the following: ❑ A primary key field that uniquely identifies each row in the database ❑ Fields designed to store textual data about each player (in varchar fields) ❑ Fields that store date and time information ❑ Flags indicating whether or not different fields require values In this table, the primary key is the PlayerID field, which stores numeric values (integers) that are unique to each player in the database This field, along with the FirstName and LastName fields, is marked as not allowing null values In other words, if you enter a row of data in the table, you must 666 Wrox United Database Design enter values for each of these fields However, the PlayerID field will be filled with an auto-generated number for you (due to the way it is configured), so the only data you must enter when you create a new row is the full name of the new player The remaining information describing the player is optional You don’t have to specify which position the player occupies, and you don’t have to specify when he or she joined Note that a varchar field is a field that stores character data of varying length The number in brackets is the maximum number of characters that can be stored in that field If the field contains less than the maximum length, it occupies less space in the database A char field, by comparison, always takes up the same size in the database, no matter how much of the available space is filled with data Figure C-2 shows an example of some data from the Players table Figure C-2 This screenshot comes straight from Visual Web Developer You can right-click any database table in the Database Explorer and select Show Table Data to try this out for yourself The Goals Table The Goals table relates directly to the Players table, because players score goals during a match The following shows the structure of the Goals table 667 Appendix C Field Data Type Allow Nulls GoalID (Primary Key) int No FixtureID (Foreign Key) int Yes PlayerID (Foreign Key) int Yes Time int Yes Notice that one of the fields in this table is the PlayerID field, which will store an integer value corresponding to the ID of one of the players in the Players table, so if Dave Dickenson scored the first goal for Wrox United, the goal in the table with GoalID of will have a PlayerID of Dave could later score another goal for Wrox United, so another record in the Goal table would be created with another unique value for GoalID, but with the same PlayerID This type of field is called a foreign key because it relates directly to a primary key in another table There is another field in the Goals table for storing ID values, which is the FixtureID field This links each goal to a particular fixture Because players could score many goals at a single fixture, the relationship between the Fixtures table and the Goals table is similar to that of the Players table and the Goals table This sort of relationship — where one fixture can contain many goals, or where one player could score many goals — is known as a one-to-many relationship The Fixtures Table The Fixtures table is structured as shown here Field Data Type Allow Nulls FixtureID (Primary Key) int No FixtureDate datetime No FixtureType varchar(10) Yes GoalsFor smallint Yes GoalsAgainst smallint Yes Notes text Yes Opponents varchar(50) No For each match played by the Wrox United team, there is an entry in the Fixtures table Because fixtures can be arranged several months in advance, the fixture date has to be entered as soon as the fixture is arranged, and the opponents have to be entered The number of goals scored can be entered later, after the match has been played 668 Wrox United Database Design The MatchReports Table After each match has taken place, it’s up to the reporters to write up the details of the match so that fans can read all about it later These reports are stored in the MatchReports table, which is structured like as shown here Field Data Type Allow Nulls ReportID (Primary Key) int No FixtureID (Foreign Key) int No Report text Yes MemberName varchar(50) No This table also links to the Fixtures table by including a FixtureID field in this table, linking a match report to a specific fixture The MemberName field stores the name of the reporter The Gallery Table The Gallery table is used to store details of pictures uploaded by fan club members The fields defined in this table are shown here Field Data Type Allow Nulls PictureID (Primary Key) int No FixtureID (Foreign Key) int Yes UploadedByMemberName varchar(50) Yes Notes text Yes PictureURL varchar(50) No Each picture can relate to a specific fixture (notice the FixtureID field); however, because this field allows the use of null values, this implies that pictures not necessarily have to relate to fixtures Standalone Tables The two standalone tables in the database are the Opponents table and the News table The Opponents Table The Opponents table stands on its own in the database, and is defined as shown here The reason the Opponents table is on its own is a bit unfortunate, but the opposing team may decide to change its name at some point in the future, which would change the name of all fixtures that Wrox United played against them in the past if they were related By keeping the tables separate, and only using a name for each team, the name of the opponent in any particular match is preserved 669 Appendix C Field Data Type Allow Nulls OpponentID (Primary Key) int No Name varchar(50) Yes Won int Yes Drawn int Yes Lost int Yes Points int Yes TotalGoalsFor int Yes TotalGoalsAgainst int Yes This table can be updated with results of matches to maintain a tally of how well the Wrox United team is performing in the league The News Table The News table, described here, contains all of the news stories from the front page of the Wrox United site Field Data Type Allow Nulls NewsID (Primary Key) Int No DateToShow datetime No Description text Yes PictureURL varchar(50) Yes Category varchar(50) Yes Title varchar(50) Yes Notice that each news item requires that a date be entered for each story, so that a story can remain hidden until a certain date has passed Wrox United Store Tables The online shopping experience on the Wrox United site relies on data stored in three tables: the Orders table, the Products table, and the OrderLines table These tables are heavily reliant on each other The Orders Table The Orders table, described here, contains a unique ID containing the main order details for an order 670 handling exceptions H handling exceptions, 7, 564 best practices, 579 Exception object, 565–566 global, 579–581 logging exceptions, 573–576 mailing exceptions, 576–578 raising exceptions, 578 trapping exceptions, 566–573 Wrox application, 10 hard disk requirements, 648 Hashtable collection, 299, 542 element, HTML, 64 health monitoring, maintenance, 610–617 element WebApplicationLifetimeEvent, 611 WebAuditEvent, 612 WebAuthenticationFailureAuditEvent, 612 WebAuthenticationSuccessAuditEvent, 612 WebBaseErrorEvent, 611 WebErrorEvent, 611 WebFailureAuditEvent, 612 WebHeartbeatEvent, 611 WebManagementEvent, 611 WebRequestErrorEvent, 612 WebRequestEvent, 611 WebSuccessAuditEvent, 612 WebViewStateFailureAuditEvent, 612 HelpLink property, Exception object, 565 hierarchical data source controls, 261 hierarchical data-bound controls, 261 HTML (Hypertext Markup Language)   element, 65 element, 64 attributes, 62 CSS property, 709–711 element, 64 brackets, 62 element, 63, 66 elements, 62 files, deployment and, 598 element, 64 element, 64 722 element, 63 element, 64 element, 64 overview, 62–66 rendering, 63 element, 64 element, 63 element, 63 tags, categories, 704, 709 element, 63 element, 64 element, 63 XHTML, 66–68 HTML controls, 82–83 Toolbox, 71 HTML panel, Toolbox, 18 HTTP (HyperText Transfer Protocol), 175 state, 176–177 System Web settings, 45 HTTP-GET, transmitting Web services, 431–432 HTTP-POST, transmitting Web services, 431–432 Hyperlink control, 81 I Identity, security and, 102 IDEs (Integrated Development Environments), VWD, 10 if statement, decisions, 312–315 IIS setup, 654 Wrox United installation and, 662 IMA, obtaining, 504 Imagecontrol, 81 ImageButton control, Click event and, 186 images files, deployment and, 598 index page, catalog, 464, 467, 470 IndexOf method, 293 indirect events, 193–195 inheritance, 338–343 CSS, 693 inherits, attribute, 351 inline styles, 692 InnerException property, Exception object, 565 INSERT INTO statement, new records, 269–271 Insert method, 293 INSERT statement, 264 new records, 269–271 Inserted event, SqlDataSource control, 187 installation troubleshooting, 663–664 VWD, 648–653 Wrox United, 658 Development Server and, 661 IIS and, 662 network services, 659 license files, deployment and, 598 life cycle of web service, 430 calling web services, 431 responses, 435 responses, returning, 433–435 transmitting web services, 431–433 LineNumber property, SqlException object, 566 HTML element, 64 LinkButton control, Click event and, 186 ListBox controls, 81, 208, 218 ListDictionary collection, 542 local variables, 344 VWD and, 661 Windows XP Home Edition, 661 instances, 327 instrumentation, maintenance, 610–617 int data type, 286 intermediate code, 356 internal Accessors, classes, 328 internal variables, 336–337 HTML element, 63 HTML element, 64 IsInRole( ) method, 404 ItemDataBound event DataItem property, 192 ItemIndex property, 192 ItemType property, 192 ItemIndex property, ItemDataBound event, 192 ItemType property, ItemDataBound event, 192 localOnly attribute, element, 588 logging exceptions, 573–576 logical operators, 310–311 login, e-commerce, 503 security, 103 Wrox application, Login controls, 103 Login panel, Toolbox, 18 LoggedIn event, Login control, 187 logical operators !, 310 &&, 310 ^, 310 ||, 310 login, Wrox United application, Login control, 103 VWD toolbox, 70 Login panel, Toolbox VWD, 18 LoginError event, Login control, 187 LoginStatus control, introduction, 103 LoginView control, introduction, 103 Logon controls Authenticate event, 187 LoggedIn event, 187 LoginError event, 187 long data type, 286 loops loop, 317–318 for loop, 318–319 foreach loop, 319–321 while loop, 317–318 L Label control, 81 LastIndexOf method, 293 layout accessibility, 172 best practices, 172–173 bugability, 172 efficiency, 172 learnability, 172 memorability, 172 satisfaction, 172 usability, 172 less than (

Ngày đăng: 09/08/2014, 18:22

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan