|
CHAPTER 19
MyInfo Component |
| The MyInfo component allows you to maintain an encapsulated list of named string values that you use often throughout your site. This component was ostensibly designed (according to the documentation) for use with Personal Web Server (PWS), but it is also useful within Internet Information Server (IIS) ASP applications. Each site can have only a single MyInfo component, and this component can contain as many values as you wish. This component helps you maintain this information by giving you a convenient, easy-to-use interface. Each value you store using the MyInfo object is stored in a text file on the web server. To access the value, you simply refer to the name of the object, followed by the dot operator, followed by the name of the valueexactly as if your value were another property of the MyInfo object. Assuming your site has a single MyInfo object called myinfoObj defined with application-level scope, you can retrieve any of its values (custom or not) using simply the syntax ObjName.PropertyName that you have used repeatedly. The example code at the end of this chapter demonstrates this. Accessory Files/Required DLL Files myinfo.dll The dynamic link library for the MyInfo component. It is installed with IIS. myinfo.xml The file in which your MyInfo component stores its values. (Note: You cannot change this filename. The component is hardcoded to look in this file.) This is a standard XML file.* The following is an example of a myinfo.xml file on an IIS web server: * The latest XML specification can be found at http://www.w3.org/TR/REC-xml. Accessory Files/Required DLL Files 347 MyInfo Accessory Files/Required DLL Files ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. MyInfo Summary Properties Background CommunityLocation CommunityName CommunityPopulation CommunityWords CompanyAddress CompanyDepartment CompanyName CompanyPhone CompanyWords Guestbook HomeOccupation HomePhone HomeWords Messages OrganizationAddress OrganizationName OrganizationPhone OrganizationWords PageType Personal Address PersonalMail PersonalName PersonalPhone PersonalWords SchoolAddress SchoolDepartment SchoolName SchoolPhone SchoolWords Style Title URL URLWords Collections None Methods None Events None 348 Chapter 19 MyInfo Component Accessory Files/Required DLL Files ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. <XML> <PersonalName>A. Keyton Weissinger</> <PersonalAddress>Addr1</> <PersonalPhone>Phone1</> <PersonalMail>Mail1</> <PersonalWords>Words1</> <CompanyName>CompName1</> <CompanyAddress>CompAddr1</> <MyInfo1></> <AdRot1></> <Addr1></> <Phone1></> <Mail1></> <Words1></> <CompName1></> <CompAddr1></> <objprop></> </XML> The following is an example of a myinfo.xml file on a Personal Web Server (mine): <XML> <theme>journal</> <ranWizard>-1</> <sync></> <guestbook>0</> <messages>-1</> <title>Keyton's Home Homepage</> <name>Keyton Weissinger</> <Email>keyton@home.com</> <Phone>555-1000</> <faxPhone>555-1001</> <Department>AtHome Books</> <Address1>123 Main Street</> <Address2>USA</> <Address3></> <Address4></> <Heading1>Here's a little about me:</> <Words1>I enjoy spending time with my family, programming, reading Patrick O'Brian novels, and Age of Sail history.</> <Heading2></> <Words2></> <Heading3></> <Words3></> <Heading4></> <Words4></> <intUrl>1</> <checkEmail></> <url1>http://www.avault.com</> <urlWords1>Adrenaline Vault</> <urlWords0>null</> <url0>null</> <favoriteLinks>-1</> </XML> Comments/Troubleshooting 349 MyInfo Comments/Troubleshooting ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. Finally, note that MyInfo.XML is only updated by PWS upon a reboot. Simply stopping and restarting PWS will not accomplish the task. Comments/Troubleshooting The MyInfo component is useful for storing and maintaining the many administrative values that correspond to properties of your web site in general. You may use items like the name of the webmaster, her phone number, and her email address in your applications repeatedly. You could simply declare them all as applicationlevel variables, but this is problematic, since you must save these values through code if you want them maintained through the course of a restart on your web server, for example. There are two points to remember when using the MyInfo component: Once a property has been created, it is in the MyInfo.XML file forever. You must edit this file by hand to remove it. As this is a small text file, this isnt a huge problem, but its worth mentioning. You should have only one MyInfo object per site (i.e., you should instantiate just one object per application) because there is only one MyInfo.XML file. This file could conceivably be in flux due to the actions of one MyInfo object while you are attempting to read or change a value from a second object. Contrary to the Microsoft documentation, your MyInfo object should have application-level, not session-level scope. You can use either of the following two pieces of code to instantiate a MyInfo object. The first uses Global.asa to call the Server.CreateObject method: [FROM GLOBAL.ASA] <% ' Declare local variables. Dim appMyInfo ' Instantiate a MyInfo object with Application level scope Set Application("appMyInfo") = _ Server.CreateObject("MSWC.MyInfo") ' You can now initialize the values Application("appMyInfo").PersonalName = _ "A. Keyton Weissinger" ...[additional code] %> The second uses the <OBJECT> tag: [FROM GLOBAL.ASA] <OBJECT RUNAT = SERVER SCOPE = APPLICATION ID = appMyInfo PROGID = "MSWC.MyInfo"> </OBJECT> 350 Chapter 19 MyInfo Component Properties Reference ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. Properties Reference [All Properties] infoObject.PropertyName [ = strPropertyValue] The meaning of the default properties is shown in Table 19-1. Parameters PropertyName The name of the desired property. If the property does not exist and you are attempting to retrieve its value, an empty string is the result. If, however, you use a nonexistent property name and include a value, that property is created and initialized to the designated value. Although you can add as many property names to a MyInfo object as you like, the properties shown in Table 19-1 are set up by default by Personal Web Server (those marked with an asterisk are also set up by Microsoft Internet Information Server). Table 19-1: Property Name and Description Property Name Description Background A string representing the background image for the site. CommunityLocation A string representing the location of the web sites community. CommunityName A string representing the name of the web sites community. CommunityPopulation A string representing the population of the web sites community. CommunityWords A string describing the web sites community. CompanyAddress* The address of the web sites company. CompanyDepartment The department within the web sites company. CompanyName* The name of the web sites company. CompanyPhone The phone number of the web sites company. CompanyWords A string representing any additional text associated with the web sites company. Guestbook A string indicating whether or not the guest book (from PWS) should be available on the site. HomeOccupation The occupation of the web sites owner. HomePhone The home phone number of the webmasters phone number. HomeWords A string representing any additional text associated with the web sites owner. [All Properties] 351 MyInfo [All Properties] ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. Messages Personal Web Server stores information about your personalized home page (if it is created through the wizard) using a MyInfo component. One option you have on your personal home page is a drop box that allows the user of your PWS web site to send you a personal message. The Messages property of the MyInfo component is a string that reflects whether or not this Messages form should appear on your home page. The value is by default (before you build your web page using the wizard), 1 if you have chosen to have the Messages form, and 0 if you have chosen not to have the Messages form. OrganizationAddress A string representing the address of the web sites organization. OrganizationName A string representing the name of the web sites organization. OrganizationPhone A string representing the phone number of the web sites organization. OrganizationWords Any additional text associated with the web sites organization. PageType This property is also a reflection of information you choose through the use of the Personal Web Server Home Page Wizard. However, it is from the older version (3.0) of PWS and is not the Home Page wizard for PWS 4.0. This propertys value is a number that represents whether the current site is (1) About My Company, (2) About My Life, (3) About My School, (4) About My Organization, or (5) About My Community. PersonalAddress* A string representing the address of the web sites owner. PersonalMail* The email address of the web sites owner. PersonalName* A string representing the name of the web site owner. PersonalPhone* A string representing the phone number of the web sites owner. PersonalWords* The additional text associated with the web sites owner. SchoolAddress The address of the web sites school. SchoolDepartment The department of the web sites school. SchoolName A string representing the name of the web sites school. SchoolPhone The phone number of the web sites school. SchoolWords A string representing any additional text associated with the web sites school. Style A string representing the relative URL of a style sheet for the web site. Table 19-1: Property Name and Description (continued) Property Name Description 352 Chapter 19 MyInfo Component [All Properties] ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. strPropertyValue A string that represents the new value for a given property. If the property name does not exist, it is created and initialized with the value of strPropertyValue. Example The following example code demonstrates both the instantiation of a MyInfo object and its use. First, a MyInfo object named appMyInfo is instantiated in GLOBAL.ASA: [FROM GLOBAL.ASA] <% ' Declare local variables. Dim appMyInfo ' Instantiate a MyInfo object with application-level scope. Set Application("appMyInfo") = _ Server.CreateObject("MSWC.MyInfo") ...[additional code] %> The following is from elsewhere in the ASP application and shows how to assign values to and retrieve values from the MyInfo object: <% ' You can set the default values. Application("appMyInfo").PersonalName = _ "A. Keyton Weissinger" ' You can also create (or set) new values. Application("appMyInfo").MyNewProp = _ "Custom Property Value" ...[additional code] ' Now you can use these values as you would any other ' application-level values. %> The value of the PersonalName property is <%= Application("appMyInfo").PersonalName %><BR> Title A string representing the user-defined title for the home page. URL(N) A string representing the Nth user-defined URL. This collection allows you to store multiple user-defined URLs for easy access. URLWords(N) A string representing the description of the Nth userdefined URL. This collection allows you to store the descriptions for the URLs in the URL collection. Table 19-1: Property Name and Description (continued) Property Name Description [All Properties] 353 MyInfo [All Properties] ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. The value of the MyNewProp property is <%= Application("appMyInfo").MyNewProp %><BR> Notes The only properties whose values are in any way unusual are the URL and URLWords collections. These allow you to create a collection of URLs for later use in your site. The following demonstrates the use of these properties: <% ' Set the URL for the first URL in the collection. Application("appMyInfo").URL(1) = _ "/Apps/HomeDir/Home.asp" ' Set the description for the first URL in the ' collection. Application("appMyInfo").URLWords(1) = _ "My Site's Home Page" . . . ' Now you can use these values to create a link (with a ' descriptive name) to a particular URL. %> <A HREF = "Application("appMyInfo").URL(1)"> <%=Application("appMyInfo").URLWords(1)%> </A> 354 ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition Copyright © 2000 OReilly & Associates, Inc. All rights reserved. e(csb o par If the change is really clever, the user may frequent your site (and see \par your \par content and view your sponsors advertisements) just to see that \par small change in \par content. \par Microsoft recognized this strategy as a common one and introduced an Active \par Server Pages component that makes rotating HTML content on an otherwiseunchanging \par document very easy. The server component is called the Content \par Rotator component. This component, in conjunction with a content schedule \par text \par file, allows you to set up a simple ASP script that retrieves a small \par bit of HTML. \par The component then displays this HTML snippet to the client without changing \par any part of your scripts other functions and without the hassle \par of having to switch \par files on your web server in and out. \par Note that this chapter documents the Content Rotator component 2.0 (Beta \par 3). It is \par available from Microsoft at http://www.microsoft.com/windows/downloads/default.asp. \par 304 Chapter 16 Content Rotator Component \par Accessory Files/Required DLL Files \par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition \par Copyright © 2000 OReilly & Associates, Inc. All rights \par reserved. \par Accessory Files/Required DLL Files \par Controt.DLL \par Controt.DLL is the dynamic link library containing the Content Rotator \par component. \par It must be registered on the web server before it can be instantiated \par in your \par web applications. This DLL is not installed by default when you install \par IIS. \par Content Schedule File \par The content schedule file contains HTML snippets that the Content Rotator \par component \par retrieves and displays to the client. Each HMTL snippet is in the following \par format: \par %% [#uintWeight] [//Comment] \par HTMLContentString \par where: \par %% \par Signals the beginning of an HTML snippet. Each entry must begin with the \par double percent sign or the Content Rotator component cannot distinguish \par it \par from the previous snippet. \par #uintWeight \par A pound sign followed by an unsigned integer value (between 1 and 65,535) \par that represents the relative weight of the current HTML snippet. This \par optional \par parameter represents the relative probability that the Content Rotator \par component \par will select this HTML snippet from the list of snippets. The actual \par probability of this HTML snippet being selected by the Content Rotator \par component is uintWeight divided by the total of all the snippets \par weights. \par For example, assume you have three snippets with weights of 33, 34, and \par 33. \par The first snippet would be selected 33% percent of the time, the second \par 34% \par percent, and the third 33% of the time. If a snippets weight is \par zero, that \par snippet is never chosen. The default weight is 1. \par Content Rotator Summary \par Properties \par None \par Collections \par None \par Methods \par ChooseContent \par GetAllContent \par Events \par None \par Accessory Files/Required DLL Files 305 \par Content Rotator \par Accessory Files/Required DLL Files \par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition \par Copyright © 2000 OReilly & Associates, Inc. All rights \par reserved. \par //Comment \par An optional string of comments describing the HTML snippet or its relevance. \par It is for your use in maintaining the content schedule file and is never \par displayed to the client. If a snippet requires more than one line of comments, \par start each comment with a double percent sign (%%) followed immediately \par with a double forward slash (//). \par HTMLContentString \par The actual HTML snippet that will be added to the clients display. \par This HTML \par can contain anything legal in HTML. However, you cannot have ASP script \par in \par the HTMLContentString parameter. The Content Rotator component identifies \par the beginning and end of an HTML snippet using the double percent \par signs. For this reason, you can have as many lines in your HTML snippet \par as \par you like. \par The following is an example content schedule file containing five entries: \par %% #33 // This identifies the first snippet of HTML. \par %% // This is a second line of comments. \par Click <A HREF = "http://www.movielines.com">here</A> \par to learn where the following movie line originated:<BR> \par <FONT SIZE = 3>"Most excellent."</FONT> \par %% #5 // This is snippet two. \par Click <A HREF = "http://www.horolines.com">here</A> \par to learn today's horoscope.<BR> \par %% #10 // This is snippet three. \par This line came from a great movie:<BR> \par "Humor. It is a difficult concept." \par %% #27 // This is snippet four. \par Comment your code; your replacement will appreciate \par the work.<BR> \par %% #450 // This is snippet five. \par <IMG SRC="/images/coolimg.jpg"> \par The probabilities that each snippet in the example content schedule file \par will be \par selected are shown in the following table: \par Snippet Weight Percentage \par 1 33/525 6% \par 2 5/525 1% \par 3 10/525 2% \par 4 27/525 5% \par 5 450/525 86% \par 306 Chapter 16 Content Rotator Component \par Instantiating the Content Rotator Component \par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition \par Copyright © 2000 OReilly & Associates, Inc. All rights \par reserved. \par Instantiating the Content Rotator Component \par To create an object variable containing an instance of the Content Rotator \par component, \par use the Server objects CreateObject method. The syntax for the CreateObject \par method is: \par Set objMyObject = Server.CreateObject(strProgId) \par where: \par The objMyObject parameter represents the name of a Content Rotator \par object. \par The strProgId parameter represents the programmatic ID (ProgID) \par for the \par Content Rotator component, which is IISSample.ContentRotator. \par Example \par <% \par ' The following code uses the CreateObject method of the \par ' Server object to instantiate a Content Rotator object \par ' on the server. \par Dim objContentRotator \par Set objContentRotator = Server.CreateObject( _ \par "IISSample.ContentRotator) \par %> \par For more details on the use of the CreateObject method, see its documentation \par in \par Chapter 8, Server Object. \par Comments/Troubleshooting \par The Content Rotator component is very simple to use. The few problems \par Ive \par heard of have all stemmed from errors in the syntax of the content schedule \par file. \par This component can be used for all sorts of so-and-so-of-the-day \par additions to \par any site. Creating a Tip of the day for your site is a very \par popular use for this \par component. \par Methods Reference \par ChooseContent \par objContentRotator.ChooseContent(strContentSchedFile) \par Selects an HTML snippet from the content schedule file. The snippet chosen \par by \par the Content Rotator component is selected from all the other snippets \par in the \par schedule file according to that snippets weight relative to the \par other snippets. \par When you call the ChooseContent method, the component calls the MapPath \par method of the Server object to determine the physical path for the virtual \par path you \par pass as an argument to ChooseContent. The result of this method call is \par a small \par HTML snippet that can be placed in the HTML sent to the client. \par GetAllContent 307 \par Content Rotator \par GetAllContent \par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition \par Copyright © 2000 OReilly & Associates, Inc. All rights \par reserved. \par Parameters \par strContentSchedFile \par A string value representing the virtual or relative pathname and filename \par of \par your content schedule file. You cannot use physical paths or absolute \par URLs \par (those beginning with HTTP://, //, or \\\\) for this parameter. \par Example \par <HTML> \par <HEAD> \par <TITLE>Document List</TITLE> \par <BODY> \par <% \par ' Dimension local variables. \par Dim objContentRotr \par Dim strSelHTMLContent \par ' Create an instance of the Content Rotator object. \par Set objContentRotr = _ \par Server.CreateObject("IISSample.ContentRotator") \par ' Retrieve a quotation from the Quote content schedule \par ' file for December. \par strSelHTMLContent = objContentRotr.ChooseContent( _ \par "/SchedFiles/DecemberQuotes.txt") \par ' Now you can add the content thus retrieved to the \par ' HTML sent to the client. \par %> \par Today's quote:<BR> \par <%= strSelHTMLContent %> \par ...[additional HTML and code] \par Notes \par Obviously, the more snippets of HTML code you add to the content schedule \par file, \par the less likely any one will be selected more than once in a row, assuming \par all \par have the same weight. \par You will receive an error if you attempt to call the ChooseContent method \par from \par within the GLOBAL.ASA file. \par GetAllContent \par objContentRotator.GetAllContent(strContentSchedFile) \par Retrieves all the HTML snippets listed in the content schedule file. When \par you \par display the content from the call to GetAllContent, each snippet will \par be separated \par by a horizontal rule tag (<HR>) in the HTML. \par 308 Chapter 16 Content Rotator Component \par GetAllContent \par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition \par Copyright © 2000 OReilly & Associates, Inc. All rights \par reserved. \par Parameters \par strContentSchedFile \par A string value representing the virtual or relative pathname and filename \par of \par your content schedule file. You cannot use physical paths or absolute \par URLs \par (those beginning with HTTP://, //, or \\\\) for this parameter. \par Example \par <HTML> \par <HEAD> \par <TITLE>Document List</TITLE> \par <BODY> \par <% \par ' Dimension local variables. \par Dim objContentRotr \par Dim strAllHTMLContent \par ' Create an instance of the Content Rotator object. \par Set objContentRotr = _ \par Server.CreateObject("IISSample.ContentRotator") \par ' Retrieve all the quotes from the Quote content \par ' schedule file for December. The call to GetAllContent \par ' will separate each HTML snippet from the Content \par ' Schedule file with an <HR> tag. \par strAllHTMLContent = objContentRotr.GetAllContent( _ \par "/SchedFiles/DecemberQuotes.txt") \par ' Now you can add the content thus retrieved to the \par ' HTML sent to the client. \par %> \par All quotes:<BR> \par <%= strAllHTMLContent %> \par ...[additional HTML and code] \par Notes \par The primary use for this method is for maintenance of the content schedule \par file. \par 309 \par Counters \par ASP in a Nutshell: A Desktop Quick Reference, eMatter Edition \par Copyright © 2000 OReilly & Associates, Inc. All rights \par reserved. } |