/// <summary> /// Sets the permissions to match the template on the specified directory. /// </summary> public void SetPermissions(string template, Uri url, bool exactMatch) { if (url == null) { throw new ArgumentException("Target URI is not valid.", "target"); } string filePath = Utils.GetAbsoluteFilePath(m_directory.FullName + "\\" + template + m_FileExtension, false, false, false); // nothing more to do if no file. if (filePath == null) { return; } string urlMask = null; if (!exactMatch) { urlMask = url.Scheme; urlMask += "://+:"; urlMask += url.Port; urlMask += url.PathAndQuery; if (!urlMask.EndsWith("/")) { urlMask += "/"; } } else { urlMask = url.ToString(); } FileInfo templateFile = new FileInfo(filePath); List <HttpAccessRule> httpRules = new List <HttpAccessRule>(); HttpAccessRule.SetAccessRules(urlMask, httpRules, true); }
/// <summary> /// Sets the permissions to match the template on the specified directory. /// </summary> public void SetPermissions(string template, Uri url, bool exactMatch) { if (url == null) { throw new ArgumentException("Target URI is not valid.", "target"); } string filePath = Utils.GetAbsoluteFilePath(m_directory.FullName + "\\" + template + m_FileExtension, false, false, false); // nothing more to do if no file. if (filePath == null) { return; } string urlMask = null; if (!exactMatch) { urlMask = url.Scheme; urlMask += "://+:"; urlMask += url.Port; urlMask += url.PathAndQuery; if (!urlMask.EndsWith("/")) { urlMask += "/"; } } else { urlMask = url.ToString(); } FileInfo templateFile = new FileInfo(filePath); FileSecurity security1 = templateFile.GetAccessControl(AccessControlSections.Access); List <HttpAccessRule> httpRules = new List <HttpAccessRule>(); foreach (AuthorizationRule rule in security1.GetAccessRules(true, true, typeof(NTAccount))) { FileSystemAccessRule fsr = rule as FileSystemAccessRule; if (fsr != null) { HttpAccessRule httpRule = new HttpAccessRule(); httpRule.UrlPrefix = urlMask; httpRule.IdentityName = fsr.IdentityReference.Translate(typeof(NTAccount)).ToString(); httpRules.Add(httpRule); if ((fsr.FileSystemRights & FileSystemRights.ChangePermissions) != 0) { httpRule.Right = ApplicationAccessRight.Configure; } else if ((fsr.FileSystemRights & FileSystemRights.WriteData) != 0) { httpRule.Right = ApplicationAccessRight.Update; } else if ((fsr.FileSystemRights & FileSystemRights.ReadData) != 0) { httpRule.Right = ApplicationAccessRight.Run; } } } HttpAccessRule.SetAccessRules(urlMask, httpRules, true); }