In the process of uploading a file with FileUp, your web application will be performing some basic file system tasks such as caching, saving and renaming that require you to understand NTFS permissions.
When an upload request is received on the server, FileUp has two responsibilities that may require interaction with the server's file system:
In order to parse through an upload request, FileUp must be able to cache the request, either to disk or memory. Caching the upload request to disk requires "Read", "Write" and "Modify" NTFS permissions on the caching directory. Later, when FileUp is instructed to save the file, these same permissions are required on the directory to which the files will be saved.
In ASP
FileUp will cache the upload request as soon as any element of the upload request, such as a file or a form element, is called in the script. At that point, FileUp will check to see if its Path property has been populated. If it has, it will cache the upload request to this directory. Setting the path property before referencing any files or form elements is considered "best practice"; however, if the Path property has not yet been set to a valid path, FileUp will check the web server’s system TEMP variableand attempt to cache the upload request there.
The exception to this case is when the UseMemory property of FileUp is set to "true". The default value of UseMemory is "false", meaning the upload will cache to disk. If UseMemory is set to "true", FileUp will not cache to disk, but will instead cache to memory. Caching to memory requires neither a directory nor NTFS permissions. You will still however, need to understand how to set NTFS permissions on the directory to which the upload is finally saved, if you call “Save�? or “SaveAs�? on an uploaded file.
In the following code sample, you can see that following best practice, on Line 9, the Path property is set immediately after instantiating FileUp. By setting this property immediately after instantiating FileUp, you can be assured that FileUp will cache to the directory specified in the Path property. FileUp is forced to cache the upload when the first form element is accessed, at line 11, and because the path property has been set already, FileUp will cache to “C:\MyCachingDirectory�?.
Line 1: | '--- Declarations |
Line 2: | Dim oFileUp |
Line 3: | '--- Instantiate the FileUp object |
Line 4: | Set oFileUp = Server.CreateObject("SoftArtisans.FileUp") |
Line 5: | '--- Set the Path property to the location you wish to |
Line 6: | '--- temporarily cache the incoming file before saving |
Line 7: | '--- Note: This property should be set immediately after |
Line 8: | '--- instantiating the FileUp object |
Line 9: | oFileUp.Path = “C:\MyCachingDirectory�? |
Line10: | '--- Confirm that the control “myFile1�? is a file input control |
Line11: | If IsObject(oFileUp.Form("myFile1")) Then |
If the Path property has been set to a valid directory, when the Savemethod is called on any file, the final saving directory will be taken from the Path property. If SaveAs is used in conjunction with a new directory path, that directory will be used instead. Should the Save method be called without having specified a path, FileUp will attempt to save the file(s) to the directory specified in the system TEMP variable.
NTFS permissions need to be granted to users or groups. You will therefore need to understand what identity FileUp assumes.
The default behavior of any object running in a web page is to assume the identity of the web application. Because you must be certain of the identity of FileUp in order to correctly set NTFS permissions, some less commonly used means of changing the identity of FileUp have been listed as well.
This dialog shows the username and password of the account used by your web application when anonymous access is granted. The default account is the IUSR account, "IUSR_[machine_name]" and the password is controlled by IIS. The IUSR account is a local account and a member of the group "guests". This account can be changed, but this has implications outside the scope of this tutorial. If you do decide to change this account, consult the documentation for IIS to determine what other actions need to be taken (for example, granting the right to “Log on locally�? to the new user account).
Assuming that you do not change this account, the IUSR account is the account to which you must grant the appropriate NTFS permissions when FileUp is assuming the identity of your web application.
Change the identity of FileUp by using FileManager.
FileManager is distributed with FileUp. By calling FileManager’s LogOnUserand RevertToSelf methods, you can change FileUp’s identity within the ASP or ASP.NET script, without changing the identity of the entire web application in IIS. To be certain of FileUp’s identity, you should check your code for calls to FileManager’s LogOnUser/RevertToSelf methods. For more information on using LogOnUser/RevertToSelf, please see the FileManager Programmer's Reference
Confirm identity by using FileManager.
With any of these web application or page level means of setting identity (in IIS, in script with FileManager), you can confirm your understanding of the identity assumed by your web application by using SoftArtisans FileManager to report the identity with the CurrentUser property. For more information on the CurrentUserproperty and a code snippet, please see the FileManager Programmer's Reference.
Set FileUp's identity at the dll level with a COM+ server package installation.
Change the identity of FileUp by installing FileUp in COM+ as a server package with a specified identity. If FileUp is installed in COM+ as a server package, an identity can be specified. When the FileUp web application runs, it will run as the identity specified in IIS, but FileUp itself will run as the user specified in COM+. Because the identity is changing in the COM+ layer and not in the web application layer, tools such as FileManager’s CurrentUser property will not be able to report this identity switch. When troubleshooting identity problems, you will want to open the COM+ manager to see if FileUp’s identity is being changed by having been installed as a server package that runs as a specific account.
Once both the identity of FileUp and the caching/saving locations have been determined, NTFS permissions can be set.