【问题标题】:Which user IIS uses for access to filesIIS 使用哪个用户访问文件
【发布时间】:2013-04-02 09:10:42
【问题描述】:

我有一个 ASP.NET 应用程序,它使用项目目录中的一些文件(许可证、日志等)。 我需要检查文件权限的方法。 我写了这个:

public static bool IsCurrentUserHaveAccessToFile(string filePath,
                                                 FileSystemRights accessType)
{
    WindowsIdentity currentUser = WindowsIdentity.GetCurrent();
    WindowsPrincipal principal = new WindowsPrincipal(currentUser); 
    FileSecurity security = File.GetAccessControl(filePath);
    var rights = security.GetAccessRules(true, true, typeof(NTAccount));
    foreach (FileSystemAccessRule right in rights)
    {
        NTAccount ntAccount = right.IdentityReference as NTAccount;
        if (principal.IsInRole(ntAccount.Value) && 
            right.AccessControlType == AccessControlType.Deny && 
            right.FileSystemRights.Contains(accessType))
        {
            log.Debug(string.Format("Checking user {0} for access permissions {1} to file {2} - DENY", currentUser.Name, accessType, filePath));
             return false;
        }
    }
    log.Debug(string.Format("Checking user {0} for access permissions {1} to file {2} - ALLOW", currentUser.Name, accessType, filePath));
    return true;
}

这个方法获取一个当前用户并且..好吧,你可以看到它:)

问题是:真的是用来访问文件的用户吗? 如果 IIS 使用了与当前用户不同的其他用户,我如何以编程方式获取它?

【问题讨论】:

    标签: asp.net windows iis permissions


    【解决方案1】:

    取决于您的代码托管位置。 This 可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      相关资源
      最近更新 更多