Saturday, February 14, 2015

Powershell to add Read permission on all files in a directory

Recently I needed to update all the files in a specific directory, adding Read permission for the "Users" NTFS group.  Here is a Powershell script to do that.  It can be easily modified to update other users/groups or different permission sets.

$base = "C:\somefolder"
$files = get-childitem $base
foreach ($file in $files) {
    $Acl = Get-Acl $file.FullName
    $Ar = New-Object  system.security.accesscontrol.filesystemaccessrule("Users","Read","Allow")
    $Acl.SetAccessRule($Ar)
    Set-Acl $file.FullName $Acl
}

Wednesday, February 4, 2015

Basic rules for using ResolveClientUrl in master pages (ASP.NET)

When writing ASP.NET Web Forms, the basic rules for using ResolveClientUrl in master pages are:
<img src="<%= ResolveClientUrl("~/x/resource.jpg")%>" />
<script src="<%= ResolveClientUrl("~/x/resource.js")%>"></script>
If you want to use ResolveClientUrl in the master page <head> section for script tags:
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
   <script src="<%= ResolveClientUrl("~/x/resource.js")%>"></script>
</asp:PlaceHolder>

You do not need to use ResolveClientUrl for CSS link elements in the <head> section (they will automatically be resolved by ASP.NET).

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...