Beispiel #1
0
        private static void CheckExecutableType(NodeHead nodeHead, string actioName)
        {
            if (nodeHead == null)
            {
                return;
            }

            // check if the extension interests us
            if (!RepositoryTools.IsExecutableExtension(Path.GetExtension(nodeHead.Name)))
            {
                return;
            }

            // If this is not an action request: if the extension indicates an executable file,
            // but the type is wrong OR the user does not have Run application
            // permission: rewrite the action to simply return the text of the file.
            if (string.IsNullOrEmpty(actioName) && (!RepositoryTools.IsExecutableType(nodeHead.GetNodeType()) || !SecurityHandler.HasPermission(nodeHead, PermissionType.RunApplication)))
            {
                PortalContext.Current.ActionName = "BinarySpecial";

                // Workaround: at this point we cannot change the action in any other way: we need
                // to rewrite the context to point to the binary highlighter page instead of the
                // executable content itself. This is how we prevent executing the file and allow
                // only showing the text content of the file (if Open permission is present).
                var action = HttpActionManager.CreateAction(PortalContext.Current);
                action.Execute();
            }
        }