I want to check whether IUSER group has write permission on a folder or not via code. In order to test that I manually gave the write permission to IUSR group on my folder:
Here is the code I have written to check that:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.ObjectModel" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Security.Principal" %>
<%@ Import Namespace="System.Security.AccessControl" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
try
{
string FilePath = @"D:\\Shared";
FileSystemSecurity security;
if (File.Exists(FilePath))
{
security = File.GetAccessControl(FilePath);
}
else
{
security = Directory.GetAccessControl(Path.GetDirectoryName(FilePath));
}
foreach (AccessRule rule in security.GetAccessRules(true, true, typeof(NTAccount)))
{
Response.Write("<br/>");
Response.Write(string.Format("Identity = {0}; Access = {1}",
rule.IdentityReference.Value, rule.AccessControlType));
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
</script>
As you can see the IUSR group is not coming in that list.
My question here is that what I missing which is preventing that IUSR group to come in that list.
Do I need to add some special check to check IUSR permission?