addVirtualDirectory
addVirtualDirectory(virtualpath: String;
physicalpath: String;
maxAge: ParamListType) typeMethod;
The addVirtualDirectory method of the Orb class adds the directory specified by the physicalpath parameter as a virtual directory that is accessible from URLs starting with the path specified by the virtualpath parameter.
The maxAge parameter is optional. It can be omitted or it can contain a single Integer property. If a value is specified for the maxAge parameter, all requests to the virtual directory include a hint to web browsers that the requested resource can be cached for the number of seconds specified by the maxAge parameter and not be requested again until this period expires, even if the web page is refreshed. This can dramatically improve performance for static assets but can leave browsers displaying out‑of‑date assets if the asset changes.
This method is provided for convenience and is intended for use during development. It is recommended that for production, assets be served from a web server or other gateway.
All files located in the directory specified by the physicalpath parameter are accessible from web requests. For example:
-
If the directory C:\inetpub\wwwroot contains the following files:
-
foo.png
-
baz.js
-
private\secret.txt
-
-
If a virtual directory is added with the following method call:
addVirtualDirectory("/stuff", "C:\inetpub\wwwroot"); -
A request to:
-
/stuff/foo.png responds with the contents of foo.png in the directory.
This request could be made from an HTML <img> tag; for example, <img src="/stuff/foo.png" alt="Foo">.
-
/stuff/baz.js responds with the contents of baz.js.
This request could be made from an HTML <script> tag; for example, <script src="/stuff/baz.js"></script>.
-
In the previous example, a request to /stuff/private/secret.txt responds with the contents of private\secret.txt as the private directory is under the specified path. It is your responsibility to ensure that sensitive files are not exposed when using the addVirtualDirectory method.
