public static HttpNamespaceAcl[] QueryHttpNamespaceAcls() { var result = new List<HttpNamespaceAcl>(); CallHttpApi( delegate { uint token = 0; uint retVal; do { HTTP_SERVICE_CONFIG_URLACL_QUERY inputConfigInfoQuery = new HTTP_SERVICE_CONFIG_URLACL_QUERY { QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext, dwToken = token }; IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_QUERY))); Marshal.StructureToPtr(inputConfigInfoQuery, pInputConfigInfo, false); IntPtr pOutputConfigInfo = IntPtr.Zero; int returnLength = 0; const HTTP_SERVICE_CONFIG_ID queryType = HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo; try { int inputConfigInfoSize = Marshal.SizeOf(inputConfigInfoQuery); retVal = HttpQueryServiceConfiguration(IntPtr.Zero, queryType, pInputConfigInfo, inputConfigInfoSize, pOutputConfigInfo, returnLength, out returnLength, IntPtr.Zero); if (ERROR_NO_MORE_ITEMS == retVal) break; if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122 { pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength); try { retVal = HttpQueryServiceConfiguration( IntPtr.Zero, queryType, pInputConfigInfo, inputConfigInfoSize, pOutputConfigInfo, returnLength, out returnLength, IntPtr.Zero); ThrowWin32ExceptionIfError(retVal); var outputConfigInfo = (HTTP_SERVICE_CONFIG_URLACL_SET) Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_URLACL_SET)); var resultItem = new HttpNamespaceAcl { UrlPrefix = outputConfigInfo.KeyDesc.pUrlPrefix, SecurityDescriptor = outputConfigInfo.ParamDesc.pStringSecurityDescriptor }; result.Add(resultItem); token++; } finally { Marshal.FreeCoTaskMem(pOutputConfigInfo); } } else { ThrowWin32ExceptionIfError(retVal); } } finally { Marshal.FreeCoTaskMem(pInputConfigInfo); } } while (NOERROR == retVal); }); return result.ToArray(); }
public static HttpNamespaceAcl[] QueryHttpNamespaceAcls() { var result = new List <HttpNamespaceAcl>(); CallHttpApi( delegate { uint token = 0; uint retVal; do { HTTP_SERVICE_CONFIG_URLACL_QUERY inputConfigInfoQuery = new HTTP_SERVICE_CONFIG_URLACL_QUERY { QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext, dwToken = token }; IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_QUERY))); Marshal.StructureToPtr(inputConfigInfoQuery, pInputConfigInfo, false); IntPtr pOutputConfigInfo = IntPtr.Zero; int returnLength = 0; const HTTP_SERVICE_CONFIG_ID queryType = HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo; try { int inputConfigInfoSize = Marshal.SizeOf(inputConfigInfoQuery); retVal = HttpQueryServiceConfiguration(IntPtr.Zero, queryType, pInputConfigInfo, inputConfigInfoSize, pOutputConfigInfo, returnLength, out returnLength, IntPtr.Zero); if (ERROR_NO_MORE_ITEMS == retVal) { break; } if (ERROR_INSUFFICIENT_BUFFER == retVal) // ERROR_INSUFFICIENT_BUFFER = 122 { pOutputConfigInfo = Marshal.AllocCoTaskMem(returnLength); try { retVal = HttpQueryServiceConfiguration( IntPtr.Zero, queryType, pInputConfigInfo, inputConfigInfoSize, pOutputConfigInfo, returnLength, out returnLength, IntPtr.Zero); ThrowWin32ExceptionIfError(retVal); var outputConfigInfo = (HTTP_SERVICE_CONFIG_URLACL_SET) Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_URLACL_SET)); var resultItem = new HttpNamespaceAcl { UrlPrefix = outputConfigInfo.KeyDesc.pUrlPrefix, SecurityDescriptor = outputConfigInfo.ParamDesc.pStringSecurityDescriptor }; result.Add(resultItem); token++; } finally { Marshal.FreeCoTaskMem(pOutputConfigInfo); } } else { ThrowWin32ExceptionIfError(retVal); } } finally { Marshal.FreeCoTaskMem(pInputConfigInfo); } } while (NOERROR == retVal); }); return(result.ToArray()); }