private static unsafe void ReserveURL(string networkURL, string securityDescriptor) { uint retVal = ErrorCodes.NOERROR; retVal = HttpApiNative.HttpInitialize(HttpApiConstants.HTTPAPI_VERSION_2, HttpApiConstants.HTTP_INITIALIZE_CONFIG, IntPtr.Zero); if (ErrorCodes.NOERROR == retVal) { try { HTTP_SERVICE_CONFIG_URLACL_KEY keyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURL); HTTP_SERVICE_CONFIG_URLACL_PARAM paramDesc = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor); HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSet = new HTTP_SERVICE_CONFIG_URLACL_SET(); inputConfigInfoSet.KeyDesc = keyDesc; inputConfigInfoSet.ParamDesc = paramDesc; retVal = HttpApiNative.HttpSetServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, ref inputConfigInfoSet, Marshal.SizeOf(inputConfigInfoSet), IntPtr.Zero); } finally { HttpApiNative.HttpTerminate(HttpApiConstants.HTTP_INITIALIZE_CONFIG, IntPtr.Zero); } } if (ErrorCodes.ERROR_ALREADY_EXISTS == retVal) { throw new ArgumentException("A reservation for this URL already exists."); } else if (ErrorCodes.NOERROR != retVal) { throw new Win32Exception((int)retVal); } }
private static void FreeURL(string networkURL, string securityDescriptor) { uint retVal = (uint)ErrorCodes.NOERROR; retVal = HttpApiNative.HttpInitialize(HttpApiConstants.HTTPAPI_VERSION_2, HttpApiConstants.HTTP_INITIALIZE_CONFIG, IntPtr.Zero); if ((uint)ErrorCodes.NOERROR == retVal) { HTTP_SERVICE_CONFIG_URLACL_KEY urlAclKey = new HTTP_SERVICE_CONFIG_URLACL_KEY(networkURL); HTTP_SERVICE_CONFIG_URLACL_PARAM urlAclParam = new HTTP_SERVICE_CONFIG_URLACL_PARAM(securityDescriptor); HTTP_SERVICE_CONFIG_URLACL_SET urlAclSet = new HTTP_SERVICE_CONFIG_URLACL_SET(); urlAclSet.KeyDesc = urlAclKey; urlAclSet.ParamDesc = urlAclParam; int configInformationSize = Marshal.SizeOf(urlAclSet); retVal = HttpApiNative.HttpDeleteServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, ref urlAclSet, configInformationSize, IntPtr.Zero); HttpApiNative.HttpTerminate(HttpApiConstants.HTTP_INITIALIZE_CONFIG, IntPtr.Zero); } if ((uint)ErrorCodes.NOERROR != retVal) { throw new Win32Exception(Convert.ToInt32(retVal)); } }