Programming | Advanced 6.3.2 Sa-fileup Components
On many web sites, a general requirement is what is the ability of the server to accept the files sent by the client? In IIS 4.0, Microsoft provided a Posting Acceptor component to do this, and the component is not available in the standard installation of IIS 5.0 and ASP 3.0, which is required if you install site Server Express. You can download the component from the Microsoft Web site http://www.microsoft.com/windows/software/webpost/post_accept.htm.
However, many people find that Posting acceptor components are functionally limited and difficult to program. Now a popular alternative is the Sa-fileup component from software artisans. Unlike the Posting Acceptor component (an ISAPI filter only), the Sa-fileup component is a true ActiveX DLL server component that is easily integrated into an ASP Web page. This means that you can use the same technologies that are used on other ASP pages or components to set page security and restrict user access. The component can also be run on a mts/com+ environment.
Tutorials using the Sa-fileup component can be found on the http://www.activeserverpages.com/upload/site, so only the results are given here. The example in this chapter includes a sample page that uses the component (in the Safileup subdirectory under the Chapter06 directory) to learn how to use the component and, if necessary, from the Software Artisans Web site http:// A copy of the sa-fileup is downloaded from the www.softartisans.com/.
Using the Sa-fileup component
The sample page of the Sa-fileup component creates a simple page that contains a FILEUPLOAD element and a button, and uses the HTML INPUT element, as shown in Figure 6-28:
Figure 6-28 Sample pages using the Sa-fileup component
<form action= "Safileup_response.asp"
Enctype= "Multipart/form-data" method= "POST" >
...
<input type= "FILE" name= "FILE1" >
...
<input type= "SUBMIT" name= "SUB1" value= "Upload File" >
...
</FORM>
When the user submits the form, the content is routed to the server, and the ASP page creates a component instance and begins uploading the information to the server, which later returns a series of data describing the uploaded file, as shown in Figure 6-29:
Figure 6-29 Results of using the Sa-fileup component
The Sa-fileup component reads the file and registers it on the server in the form of a standard disk file or binary database data. With it, you can use ASP to control the upload process, limit the size of the upload file, or even delete the upload file, can also dynamically change its name and upload file location.
6.3.3 Regex Registry Access Component
A sample component provided by Microsoft IIS 4.0 can access the system registry on the server. This feature helps you check the version of software that you install, or check the various parameters used by IIS and the operating system.
This component was canceled in IIS 5.0, but can be obtained from other commercial versions if this feature is required. The Regex component is one of those that can access any part of the Local machine registry (if the current user is allowed to access it). In anonymous access to an ASP page, the current user is the IUSR_machinename account.
1. Members of the Regex component
The Regex component provides four ways to read and write the registry and a way to access the internal component version information, as shown in table 6-11. All information and documentation is available with the Regex component and its beta version can be downloaded from the http://www.stonebroom.com/. The sample page that comes with it is included in the example provided in this book, but you need to download the component itself.
Table 6-11 RegEx Component method and description
Method
Description
GetRegValue (registryhive,subkeystring)
Returns the default value of the given subkey from the registry, and returns an empty string if its value is inaccessible
Setregvalue (Registryhive,subkeystring,
NewValue)
In the given subkey, create or update the "default" value and set the data type to REG_SZ (string). Returns true if the update succeeds, otherwise returns false
Getregvalueex (Registryhive,subkeystring,
Valuemane,valuetype)
Returns a named value from a specific subkey, updating the variable specified by the last parameter of the method, using the data type that returns the numeric value. If the value is not accessible, an empty string is returned and reg_error as the data type
Setregvalueex (Registryhive,subkeystring,
Valuename,newvalue,valuetype)
Creates or updates a named number in a given subkey, setting the data type to the type Data_type specified by the last parameter of the method. Returns true if the update succeeds, otherwise returns false
Getinternalversionnumber ()
Returns the build number of the component, if it is a test version, and the return value contains the information
2. Using the Regex component
The Regex component provides a sample program, written in Visual Basic, that you can use to experiment with the methods it contains, which uses the Regex component to allow any portion of the system registry to be read or written to one of the supported data types or to the default string data type, as shown in Figure 6-30. A warning is displayed before any updates are made to prevent unexpected actions.
Figure 6-30 Sample program using the Regex component
There is also a simpler ASP instance that displays some of the data in the Web server registry and allows you to read and set a Test subkey. You can modify this page and use it in your own application without restrictions. Figure 6-31 shows the results of running on NT4 and IIS 4.0.
Figure 6-31 Results of another example using the Regex component
Keep in mind that changing the values in the registry may cause the system to work abnormally, and that you should back up the registry files before you edit the contents of your registry.
6.4 Summary
This chapter discusses how ASPs can use server components to add features that other components cannot provide, and also consider the difference between server components and other types of ASP objects, such as ASP-built objects and objects in the Script Runtime library.
After studying the installable components provided by ASP 3.0 and IIS 5.0, we introduced three commercial components that provide the functionality of the general requirements, as well as several common components that can be downloaded from the web, some of which are free or shared/beta versions. However, so far we still have a very important component not involved, it is ADO. Before discussing this issue, let's discuss another basic issue: error Handling and program debugging.