当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.FileInfo.GetAccessControl方法代码示例

本文整理汇总了C#中System.IO.FileInfo.GetAccessControl方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileInfo.GetAccessControl方法的具体用法?C# System.IO.FileInfo.GetAccessControl怎么用?C# System.IO.FileInfo.GetAccessControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileInfo的用法示例。


在下文中一共展示了System.IO.FileInfo.GetAccessControl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckUserFileAccessRights

        /// <summary>
        /// Supply the path to the file or directory and a user or group. 
        /// Access checks are done
        /// during instantiation to ensure we always have a valid object
        /// </summary>
        /// <param name="path"></param>
        /// <param name="principal"></param>
        public CheckUserFileAccessRights(string path,
            System.Security.Principal.WindowsIdentity principal)
        {
            this._path = path;
            this._principal = principal;

            try
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(_path);
                AuthorizationRuleCollection acl = fi.GetAccessControl().GetAccessRules
                            (true, true, typeof(SecurityIdentifier));
                for (int i = 0; i < acl.Count; i++)
                {
                    System.Security.AccessControl.FileSystemAccessRule rule =
                           (System.Security.AccessControl.FileSystemAccessRule)acl[i];
                    if (_principal.User.Equals(rule.IdentityReference))
                    {
                        if (System.Security.AccessControl.AccessControlType.Deny.Equals
                                (rule.AccessControlType))
                        {
                            AuthorizationDenyAccess(rule);
                        }
                        else if (System.Security.AccessControl.AccessControlType.
                                 Allow.Equals(rule.AccessControlType))
                        {
                            AuthorizationAllowAccess(rule);
                        }
                    }
                }

                IdentityReferenceCollection groups = _principal.Groups;
                for (int j = 0; j < groups.Count; j++)
                {
                    for (int i = 0; i < acl.Count; i++)
                    {
                        System.Security.AccessControl.FileSystemAccessRule rule =
                            (System.Security.AccessControl.FileSystemAccessRule)acl[i];
                        if (groups[j].Equals(rule.IdentityReference))
                        {
                            if (System.Security.AccessControl.AccessControlType.
                                Deny.Equals(rule.AccessControlType))
                            {
                                IdentityDenyAccess(rule);
                            }
                            else if (System.Security.AccessControl.AccessControlType.
                                   Allow.Equals(rule.AccessControlType))
                            {
                                IdentityAllowAccess(rule);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //Deal with IO exceptions if you want
                //throw e;
                AccessDenied();
            }
        }
开发者ID:neilmayhew,项目名称:pathway,代码行数:67,代码来源:CheckUserFileAccessRights.cs


注:本文中的System.IO.FileInfo.GetAccessControl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。