Search code examples
c#asp.netactive-directorytelerik

Telerik file explorer with active directory where user can see only the shared folders if AD allows them


I have a local server that has active directory (AD) with a shared folder and multiple users and users have different access rights with respect to the sub folders and files. I am implementing a web portal for accessing that folder using ASP.NET Web Forms and Telerik RadFileExplorer.

I have implemented authentication using Active Directory and I require to authenticate that user and use the web portal that uses Telerik File Explorer. Even Windows Impersonating user would work as the user logs in using the AD account. When I implement the file explorer, it allows me to explore properly, but when I host it with IIS, it gives error that states access is denied for the user. I tried implementing it using "Physical and Shared Paths" and "UNC Shared drive".

I have also implemented login validation via active directory using System.DirectoryServices. However, I want to link authentication to telerik file explorer or use windows authentication of the current logged in user.

The expected results are that the user should be able to access the file explorer and use it where the rights of that user are defined in the active directory.


Solution

  • The permissions for the directories can be checked using the System.IO.DirectoryInfo assembly. While using the CustomFileSystemProvider, add it for every directory before adding the directory to the directoryItems List.

    DirectoryInfo permissionChecker = new DirectoryInfo(dirPath);
    try
    {
        permissionChecker.GetAccessControl();
        System.Security.AccessControl.DirectorySecurity permissionCheckerDS = permissionChecker.GetAccessControl();
    }
    catch (UnauthorizedAccessException ex)
    {
        Console.WriteLine(dirPath);
        // Here when the UnauthorizedAccessException occurs, it means that the user has no access for that directory (not even read access) 
    }
    

    Similarly check the permmissions for the files before adding them to the files List.