检查IUSR组是否对文件夹具有写权限

时间:2018-08-15 05:27:46

标签: c# asp.net .net

我想通过代码检查IUSER组是否对文件夹具有写权限。为了测试我是否手动授予了文件夹中IUSR组的写许可权:

enter image description here

这是我编写的用于检查代码:

<%@ 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>

这是输出: enter image description here

您可以看到IUSR组不在该列表中。

我的问题是,我所缺少的是阻止IUSR小组进入该列表。

我需要添加一些特殊检查来检查IUSR权限吗?

1 个答案:

答案 0 :(得分:0)

Server Fault上有一篇与此有关的有用文章。主要原因是在IIS 7.5(以及可选的IIS 7)中,所有工作进程都使用应用程序池标识运行:用户“ IIS AppPool PoolName ”,这就是IUSR组不在列表中的原因。

我建议先检查apppool组,然后再检查IUSR。 然后尝试获取特定用户(而不是组),并检查读写权限,如果在此测试中成功,那就可以了。

也请检查此post以供参考。

相关问题