Link:http://output.to/sideway/default.asp?qno=120200035 Lock / Unlock Application ObjectOne of the key functions of Application Object is the application control on the server. Application.Lock MethodApplication.Lock method locks the properties of Application object by only one client at a time for preventing other clients from modification.. Syntax:Lock( Or in an ASP file. Imply <% Application.Lock %> Parameters:void This method has no parameters Return Values:void This method has no parameters Remarks:After calling the Application.Lock method, if the Application.Unlock method is not called explicitly, the server unlocks the locked Application object when the ASP file processing ends or times out. Therefore a lock on the Application object only persists for a very short time. However, if one page locks the application object and a second page tries to locks the same application object while the first page still has it locked, the second page will wait for the first to finish, or until the Server.ScriptTimeout limit is reached. If the Server.ScriptTimeout limit is reached, the following ASP error is returned which cannot be captured:
HTTP 500.100 - Internal Server Error - ASP error
To reduce the possibility of having an ASP page time out, write a COM+ object that uses the COM+ ObjectContext object to update the Application collection, and then call the COM+ object from an ASP. COM+ objects execute slightly faster than ASP pages. The application collection can be modified without locking the application object to edit. Therefore two pages can modify the same application without causing any error, however, the modification will become inconsistent. Examples:
Application.Unlock MethodApplication.UnlLock method unlocks or releases the properties of Application object by the only one client at a time for allowing other clients to modify. Syntax:Unlock( Or in an ASP file. Imply <% Application.Unlock %> Parameters:void This method has no parameters Parameters:void This method has no parameters Remarks:The Application.Lock method is cumulative, therefore for the same script, the number of Lock method calls should be equal to the number of Unlock method calls in order to fully release the application, otherwise the application remains Locked. After calling the Application.Lock method , if the Application.Unlock method is not called explicitly, the server unlocks the locked Application object when the ASP file processing ends or times out. Therefore a lock on the Application object only persists for a very short time. However, if one page locks the application object and a second page tries to locks the same application object while the first page still has it locked, the second page will wait for the first to finish, or until the Server.ScriptTimeout limit is reached. If the Server.ScriptTimeout limit is reached, the following ASP error is returned which cannot be captured:
HTTP 500.100 - Internal Server Error - ASP error
To reduce the possibility of having an ASP page time out, write a COM+ object that uses the COM+ ObjectContext object to update the Application collection, and then call the COM+ object from an ASP. COM+ objects execute slightly faster than ASP pages. The application collection can be modified without locking the application object to edit. Therefore two pages can modify the same application without causing any error, however, the modification will become inconsistent. Examples:
Link:http://output.to/sideway/default.asp?qno=120200030 HTMLEncode / URLEncode Server ObjectServer object also provides some utility functions on the server. Server.HTMLEncode MethodServer.HTMLEncode Method encodes and converts the specified string according to the HTML encoding rules. Syntax:HTMLEncode( Or in an ASP file. Imply <% Server.HTMLEncode(string) %> Parameters:string The paramete "string" specifies the string to encode. Return Values:The HTMLEncoded string. Remarks:The Server.HTMLEncode Method can be used to encode data for converting potentially unsafe characters to their HTML-encoded equivalent. If the string to be encode is not double-byte character set (DBCS), HTMLEncode converts characters as following:
If the string to be encode is double-byte character set (DBCS), HTMLEncode converts characters as following:
The encoded code will be displayed by a Web browser. And the encoded HTML page can be displayed when opened the page file as a text file. Examples:
Server.URLEncode MethodServer.URLEncode Method encodes and converts the specified string according to the URL encoding rules including escape characters . Syntax:URLEncode( Or in an ASP file. Imply <% Server.URLEncode(string) %> Parameters:string The paramete "string" specifies the string to encode. Return Values:The URLEncoded string. Remarks:The Server.URLEncode Method can be used to encode data for converting characters as following:
Examples:
Link:http://output.to/sideway/default.asp?qno=120200031 MapPath / GetLastError Server ObjectServer object also provides some utility functions on the server. Server.MapPath MethodServer.MapPath Method maps and converts the specified path including virtual path on the server, or relative path relative to the page into the corresponding physical path.. Syntax:MapPath( Or in an ASP file. Imply <% Server.MapPath(path) %> Parameters:Path The paramete "Path" specifies the relative or virtual path to map to a physical directory. For Path start with either a forword (/) or backward slash (\), the Mappath method returns a path as if Path were a full, wirtual path. For Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the ASP file being processed. Return Values:The mapped path string. Remarks:For Path start with either a forword (/) or backward slash (\), the Mappath method returns a path as if Path were a full, virtual path. For Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the ASP file being processed. The Server.MapPath Method returns the ASP 0173 error, "Invalid Path Character", if the parameter Path contains any of the following characters:
The Server.MapPath method does not check whether the path it retruns is valid or exists on the server. Because the Server.MapPath method maps a path regardless of whether the specified directories currently exist, the Server.MapPath method to map a path to a physical directory structure, and then pass that to a component that creates the specified directory or file on the server. Server.MapPath is not available to the Session_OnEnd and the Application_OnEnd events. For security reason, the AspEnableParentPaths property has a default value set to FALSE. Scripts will not have access to the physical directory structure unless AspEnableParentPaths is set to True Examples:
Server.GetLastError MethodServer.GetLastError Method gets the last error from the ASPError that describes the error condition of processing the script in an ASP file. Syntax:GetLastError( Or in an ASP file. Imply <% Server.GetLastError() %> Parameters:void This method has no parameters.. Return Values:Server.GetLastError Method returns the last instance of ASPError. Remarks:This method is available only before the .asp file has sent any content to the client. A 500;100 custom error will be generated if IIS encounters an error while processing either an .asp file or the application's Global.asa file. If a 500:100 custom error has been defined for an ASP application, it may refer to an ASP file. In this case, when an error occurs during the running of an ASP file within the application, the server automatically transfers to this ASP page via the Server.Transfer method. All of the state information from the executing ASP application will be available to the ASP file that is handlingthe error. In addition, the ASPError Object will be available, so that the properties of the error can be exposed through the ASP file that can be set up for handling the error. The Default Web sit is configured to use the file \iishelp\common\500-100.asp. Either this file or a self created file can be used for processing ASP errors. The file for processing the 500:100 custom errors can be changed through the IIS Manager. Examples:
|
Sideway BICK Blog 10/02 |