private static void EnsurePermissionSettings() { var rights = FileSystemRights.CreateDirectories | FileSystemRights.CreateFiles | FileSystemRights.ListDirectory | FileSystemRights.Modify | FileSystemRights.DeleteSubdirectoriesAndFiles; var everyone = FilePermissions.EveryoneIdentity; if (Installation.GetFileLayoutType() == FileLayoutType.Installed) { FilePermissions.SetAclForUserOnDirectory(Installation.GetConfigurationDirectory(), everyone, rights, AccessControlType.Allow); foreach (var file in Directory.GetFiles(Installation.GetConfigurationDirectory(), "*.xml")) { FilePermissions.SetAclForUserOnFile(file, everyone, rights, AccessControlType.Allow); } } FilePermissions.SetAclForUserOnDirectory(Installation.GetCacheDirectory(), everyone, rights, AccessControlType.Allow); FilePermissions.SetAclForUserOnDirectory(Installation.GetLogDirectory(), everyone, rights, AccessControlType.Allow); }
public static void SetupAspDotNet() { // On Windows 8, the Temporary ASP.NET Files directory isn't created during installation of the .NET framework, so we // need to create it ourselves. Using another temporary directory is problematic because: // (a) It can only be set in the <compilation> attribute in Web.config, but we don't want to change it globally in // WebMediaPortal (the current value should be kept for IIS setups). // (b) Changing the directory causes IIS Express to restart the application with every request, which is really bad // for performance. var tempDir = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "Temporary ASP.NET Files"); if (!Directory.Exists(tempDir)) { Log.Info("Creating ASP.NET temporary directory '{0}'", tempDir); Directory.CreateDirectory(tempDir); } // Assume that the directory is already writable when we can list all subdirectories, so nothing to do in that case. try { Directory.GetDirectories(tempDir); return; } catch (Exception) { } // Otherwise, set suitable permissions try { Log.Info("Going to give the current user write access on ASP.NET temporary directory '{0}'", tempDir); var currentUser = WindowsIdentity.GetCurrent().User; FilePermissions.SetAclForUserOnDirectory(tempDir, currentUser, FileSystemRights.FullControl, AccessControlType.Allow); } catch (Exception ex) { Log.Error("Failed to set permissions on ASP.NET temporary directory", ex); } }