Tutorials to .com

Tutorials to .com » Asp » Base » Advanced Programming ASP 3.0 (26)

Advanced Programming ASP 3.0 (26)

Print View , by: iSee ,Total views: 9 ,Word Count: 3141 ,Date: Sat, 25 Apr 2009 Time: 9:18 PM

6.2.6 Content Rotator Component
Content Rotator component, like a simplified Ad Rotator component, need to provide a schedule file content (Content Schedule File). The document contains only a text and HTML code of the text file, Content Rotator component can be automatically displayed in the page one. Scheduling table file can include any number of text entries, and the provisions of the rate of return to control page display the frequency of each entry.
1. Content schedule file
The contents of the progress of the document structure of the Ad Rotator than simple schedule file, only to be used to provide the list of all text strings from the front of the two percent increase (%%) that the statement line. In order to set the ratio of each entry (the decision to return to the page it appears in the frequency), in the two-percent behind the addition of a number, then also with a pair of forward slash symbol (/ /) to add comments. Such as:
%% 3 / / This is the first entry in the schedule text file
For more information, mail us at
<A HREF=mailto:feedback@wrox.com> Wrox Press </ A>

%% 4 / / This is a multi-line text string
<H4> Wrox Press </ H4>
<LI> Language Primers
<LI> Advanced Programming
<LI> Internet Applications
</ UL>

%% 2
Visit us on the <A HREF="http://www.wrox.com"> World Wide Web </ A>

This case, can be used to page three text strings, the ratio of 3,4 and 2 respectively, so entries will be 3 / 9, 4 / 9 and 2 / 9 of the frequency. Attention (and the Ad Rotator component, like) for each of the actual string is random, and then, as amended, was the corresponding ratio, if transferred to nine pages, may not exactly be the outcome.
2. Members of the Content Rotator Component
Content Rotator component provides only two methods for scheduling content to retrieve the contents of documents, such as shown in Table 6-5:
Table 6-5 Content Rotator Component and Description

GetAllContent (schdule_file)
Schdule_file document retrieval and display all the strings

ChooseContent (schdule_file)
Search (not shown) schdule_file documents from the appropriate content of a string

3. Content Rotator component to use
From the schedule file in order to obtain the specified section of text and HTML, can use methods of the object retrieval ChooseContent an entry, in accordance with the provisions of the contents of the document dispatch rate. Response.Write method can be used to send into the machine room in the output stream.
<% 'In VBScript:
Set objMyContent = Server.CreateObject ( "MSWC.ContentRotator")
strContent = objMyContent.ChooseContent ( "ContentRotator / content_schedule.txt")
Response.Write strContent
The code used in the same directory and page in the schedule file, if the code stored in other places, we must specify the path to the file scheduling, this can be a path relative to the root directory of the Web site or a complete physical path of the virtual path.
ObjMyContent.ChooseContent ( "\ content \ mycontent.txt") 'relative physical path
ObjMyContent.ChooseContent ( "/ demo / mycontent.txt") 'full virtual path
If you want to show the contents of scheduling all the contents of file string, you can use the object GetAllContent methods, such as the case ChooseaContent methods, scheduling must provide the path to the file. For example, the following code scheduling by the content of all the contents of the document and displayed on the page. Attention to the contents of this method is automatically inserted into the page, so no need to use Response.Write method, this method also automatically between each entry in a horizontal line.
ObjMyContent.GetAllContent ( "mycontent.txt")
In order to study the role of the Content Rotator component, from the "ASP Installable Components" to open the main menu page provides an example of the use of the front page the content of said schedule file. ChooseContent method call and an entry on the top of the page and then use the method GetAllContent scheduling document shows the contents of all entries. Content Rotator component sample page shown in Figure 6-9:

Figure 6-9 Content Rotator component sample page

6.2.7 Page Counter Component
Page Counter Component for each statistics the number of pages visited, the regular component of the statistical data on the disk into the server a text file - data file number of visits Statistics (Hit Count Data File), so in the stands or error message, the current data will not be lost.
1. Members of the Page Counter Component
Page Counter component of the document provided a way to increase the number of visits and visit to read and re-set the total count method, as shown in Table 6-6:

Hits ([Page_Path])
Return to the page specified by the Page_Path the number of visits, if the option is omitted, then Page_Path to return to the current page number of visits

PageHit ()
Increase the number of visits to the current page

Reset ([Page_Path])
Set Page_Path designated by the number of visits the page to 0, if omitted Page_Path option, then set the current page number of visits to 0

2. Page Counter Component use
The following jscript example uses language to illustrate the use of the Page Counter Component, use Server.CreateObject method to create object instance, and then call methods Hits of the current page number of visits. If the number of visits up to 5 times, while counters re-set to 0, and placed in the page with a link to the visitor through the results.
<% / / In JScript:
var objPageCount = Server.CreateObject ( 'MSWC.PageCounter');

/ / look for a command sent from the FORM section buttons

/ / Increment the counter and display the current hit count
objPageCount.PageHit ();
Response.Write ( 'You are visitor number' + objPageCount.Hits () + '<P>');

/ / We treat every fifth visitor as a winner
if (objPageCount.Hits () == 5) (
objPageCount.Reset (); / / reset the counter
Response.Write ( 'You \' re a lucky winner! <BR> ');
Response.Write ( '<A HREF="winner.asp"> Go to our winners page </ A> <BR>');
Response.Write attention in the second statement, after the slash (\) is to prevent the use of quotation marks as JScript engine to the end of the string.
This book provides a sample of the Page Counter Component page. However, due to the page in each sample using a vbscript example of this programming component. Although in a asp page, it is possible to mix scripting language, but the # include in the SSI document using the scripting language will enable the page cache problems and will cause unpredictable results. Although the scripting language different, but the sample pages with the above-mentioned work the same way. Page Counter Component sample page shown in Figure 6-10:

Figure 6-10 Page Counter component sample page
The page contains <FORM> paragraph contains two buttons, two buttons have to submit the form to re-transferred to the page.
<FORM ACTION = "<% = Request.ServerVariables (" SCRIPT_NAME ")%>" METHOD = "POST">
<INPUT TYPE="SUBMIT" VALUE=" "> Reload this page <P>
PageCounter.Reset ()
</ FORM>
At the beginning of the page, with other examples of web pages, as related in the request to find the name of the button. In this page, we have named only the second interest cmdReset button, if clicked on the button, and run the Page Counter component of the Reset method to reset the page number of visits to 0.
'look for a command sent from the FORM section buttons
If Len (Request.Form ( "cmdReset")) Then objPageCount.Reset 'reset the counter
In front of the code will call to see PageHit ways to counter is set to 1, and displayed on the page. Attention has been the use of Hits and Reset methods do not provide value for optional parameters, they are counter to operate the current page, of course, can be used in another page, and pages can be of some summary statistics.

6.2.8 Permission Checker Component
Permission Checker component to detect users visit the Web site is currently being allowed to read the account whether a particular document or visit a certain resources (only in Windows NT/2000 and not in Windows 9X). Can use it to customize the page, the page contains only the current user allowed to access the link resources, the technology to restrict access to hidden pages and resources are very useful, it can be limited so that visitors do not know these resources the existence of which does not attempt to use force to enter.
1. Permission Checker Component members
Permission Checker component is only one way, as shown in Table 6-7:
Table 6-7 Permission Checker Component and Description

HasAccess (file_path)
Check the implementation of the current page is the user account allows access to the page specified file_path. The path is a web page, document or physical resources or virtual path. Allow access if the current account, the return value of "True", otherwise the return value of "False"

2. Permission Checker Component process
Generally, unless special provisions, or visit the web page the user is anonymous, so IIS will own the Windows account to use their own visit to the page, the default value is IUSR_machinename (for example, IUSR_WROXBOX), Permission Checker component to check whether IUSR_machinename account to access the specified page or resources.
However, the Internet Services Manager through the Allow Anonymous Access option is to close on the Web site or a specified directory on the anonymous access, IIS prompts the user can be forced to enter a valid user account user name and password, and then use the account "non-anonymous access" resources.
On a website or catalog, Internet Services Manager in the Properties dialog box on the Directory Security tab to set access control. In dialogue form in Anonymous Access and Authentication Control, click the Edit button to open the Authentication Methods dialog box, turn off Anonymous Access option. Set the interface as shown in Figure 6-11:

Figure 6-11 Setting access interface
Permission Checker component when the user account with its own (rather than IUSR_machinename) visit to the page has been instantiated, it will check whether the account can access the specified resource, if it can not use anonymous access, then all users must provide Account details. You can use Windows Explorer or resources to set up each file specified permissions (in the corresponding Properties dialog box in the Security tab). Set the interface as shown in Figure 6-12:

Figure 6-12 Setting permissions interface
3. Permission Checker component to use
Permission Checker component can be used to check whether or not to use the current user to access other methods HasAccess page (any page on the site) of the authority. This book provides a series of examples of pages, Permission Checker can be used to test components, open the sample (from the ASP Installable Components to open the main menu), will see three links page, as shown in Figure 6-13:

Figure 6-13 using the Permission Checker component of the sample page
Links point to each of the pages are located in the Chapter06 directory PermissionChecker examples subdirectory. Permission Checker component to check whether the current user has permission to visit the various pages. If the user does have permission to access this page, this entry page will be a hyperlink.
'create an instance of the component
Set objPermit = Server.CreateObject ( "MSWC.PermissionChecker")

<% If objPermit.HasAccess ( "PermissionChecker/restricted_1.asp") Then%>
<A HREF="PermissionChecker/restricted_1.asp">
<% End If%>
Restricted Page Number 1
<% If objPermit.HasAccess ( "PermissionChecker/restricted_1.asp") Then%>
</ A>
<% End If%>
</ LI>
.. 'Other page links here
</ UL>
We now have access to three pages to restrict access permissions, so these three entries are hyperlinks. However, does not exist here, the fourth link (it can be removed or deleted), because the components can not use the current user (that is, IUSR_machinename) account to access it, it does not appear as hyperlinks.
Note the removal of hyperlinks to choose but only left a link to the text, in reality should be deleted and can not visit the entire entry page.
If restricted_2.asp subdirectory PermssionChecker deleted files Read (and any other) permissions, and re-transferred to the page, the corresponding entry will not appear as a hyperlink, as shown in Figure 6-14:

Figure 6-14 Delete Read permissions to the page after the show

6.2.9 MyInfo Component
MyInfo component is the first Web server in conjunction with the introduction of the individual, and used to store the server administrator to provide personal information. It can be used in ASP 3.0, in order to name / value pair, or any other type of text strings can be expressed as the permanent storage of information. The information to a text file in xml format myinfo.xml saved, this file is located at only Web server inetsrv directory. In Windows 2000, its path for the WinNT \ system32 \ inetsrv \.
Counter components and the same, just create a simple example of MyInfo component can use the Web site have access to all the pages of its information, to ensure that the default Web site on the global.asa file in the following code:
<! - Declare instance of the ASP MyInfo component with application-level scope
<OBJECT ID="objMyInfo" RUNAT="Server" SCOPE="Application" PROGID="MSWC.MyInfo">
1. MyInfo component use
MyInfo component without default properties and methods. However, attributes can be added to, simply put, is a name given to these attributes and values. For example, you can add the work environment and information partners.
<% 'In VBScript:
objMyInfo.MyManager = "Christina Chan"
objMyInfo.MyPhoneExtension = "2851"
objMyInfo.MyCarParkingSpace = "4A-17"
objMyInfo.MyComputerName = "Priscilla"
Like other components the same attributes, you can use the following numerical code retrieval.
<% 'In VBScript:
strManagerName = objMyInfo.MyManager
strPhoneExtension = objMyInfo.MyPhoneExtension
strParkingSpace = objMyInfo.MyCarParkingSpace
strComputerName = objMyInfo.MyComputerName
This is a page request in two between the value of useful storage method does not require the user's Session object. This may change for the future provides a value storage area, using these values in the next page will be automatically run when the acquisition value of these changes, thus avoiding the need to edit a large number of other pages.
This book provides a simple to use MyInfo component sample, the sample ASP Installable Components from the main menu to run, use the earlier discussion of the code set component attributes and attribute values change, as shown in Figure 6-15:

Figure 6-15 pages using MyInfo Component
Open the first page, the attributes used to create a sign of the variable SetDefaultValues, the variables stored in the user's Session object. When the page the first time in each session is open, the attribute parameter set to "default" value, after which the signs of this variable set to Yes. In the current session and re-transferred to the page, this value will no longer be re-set default values.
'an instance of the component is already created in global.asa
If Not Session ( "SetDefaultValues") = "Yes" Then
'set the properties if they're not set to the default values,
'ie if this is the first time that the page has been run
'during the current user session.
objMyInfo.MyManager = "Christina Chan"
objMyInfo.MyPhoneExtension = "2851"
objMyInfo.MyCarParkingSpace = "4A-17"
objMyInfo.MyComputerName = "Priscilla"
'set a session flag to show that the default values hve been set
Session ( "SetDefaultValues") = "Yes"
End If
Call each page, to check whether the value of the request to change the attribute value for the name of the button. This button contains a drop-down list in the text box and the <FORM>. If it is found click on the button from the drop-down list and text box collection value, and then use these values to change the relevant attribute values.
'look for a command sent from the FORM section buttons
If Len (Request.Form ( "cmdChange")) Then
strPropertyName = Request.Form ( "lstName") 'get the name of the property
strNewValue = Request.Form ( "txtValue") 'get the new value for the property
objMyInfo (strPropertyName) = strNewValue 'set the component property value
End If

Asp Base Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.