CHttpServer::CheckVirtualPath Method  
 
BOOL CheckVirtualPath(
  UINT nClientId,  
  LPCTSTR lpszVirtualPath,  
  DWORD dwFileAccess  
);

Determine if the client has permission to access the specified virtual path.

Parameters

nClientId
An unsigned integer which uniquely identifies the client session.
lpszVirtualPath
A null-terminated string which specifies the virtual path that should be checked. This path must be absolute and cannot be a NULL pointer or an empty string. The maximum length of the virtual path is 1024 characters.
dwFileAccess
An unsigned integer value which specifies the access permissions that should be checked. For a list of file access permissions, see User and File Access Constants.

Return Value

If the method succeeds, the return value is non-zero. If the client ID does not specify a valid client, the method will return zero. If the method fails, the last error code will be updated to indicate the cause of the failure.

Remarks

The CheckVirtualPath method is used to determine if the client has permission to access the virtual file or directory, based on the value of the dwFileAccess parameter. For example, if the dwFileAccess parameter has the value HTTP_ACCESS_WRITE, this method will check if the client has write permission for the file or directory. The method will return a non-zero value if the client does have the requested permission, or zero if it does not.

Applications that implement their own custom handlers for standard HTTP commands should use this method to ensure that the client has the appropriate permissions to access the requested resource. Failure to check the access permissions for the client can result in the client being able to access restricted documents and other resources. It is recommended that most applications use the default command handlers.

To obtain the path to the local file or directory that the virtual path is mapped to, use the GetClientLocalPath method.

Example

CString strPathName;

// Get the current request URL path
INT cchPathName = pServer->GetCommandResource(nClientId, strPathName);

if (cchPathName == 0)
{
    pServer->SendErrorResponse(nClientId, 500);
    return;
}

// Check if the client has write access to that resource
BOOL bAllowed = pServer->CheckVirtualPath(
                    nClientId,
                    strPathName,
                    HTTP_ACCESS_WRITE);
                
if (!bAllowed)
{
    pServer->SendErrorResponse(nClientId, 403);
    return;
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: cshtsv11.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

AddVirtualPath, DeleteVirtualPath, GetClientLocalPath, GetClientVirtualPath