System.Windows.Forms.Clipboard 适用于桌面,但不适用于 IIS

System.Windows.Forms.Clipboard works on desktop, but does not work on IIS

我有一个小模块,它正在寻找剪贴板中的图像,如果有,就将其显示在页面上。这在我的桌面上效果很好,但在 IIS 上托管时永远不会进入 System.Windows.Forms.Clipboard.ContainsImage() 。服务器端应用程序不能使用任何超出目的的概念,例如 windows 剪贴板?

        if (System.Windows.Forms.Clipboard.ContainsImage())
        {
            img = System.Windows.Forms.Clipboard.GetImage();
            imgBytes = imageToByteArray(img);
            string imgString = Convert.ToBase64String(imgBytes, 0, imgBytes.Length);                
            clipBoardImg.ImageUrl = "data:image/jpeg;base64," + imgString;
            clipBoardImg.Visible = true;
        }

如果您尝试在 IIS 上访问剪贴板,请尝试在服务器而不是客户端上访问它。这肯定也会在服务器端失败,因为您的服务器进程中没有屏幕(您不是用户交互的)。

你应该做的是将这段代码转换成客户端的东西(例如javascript),这很难,因为你不能只从客户端浏览器访问剪贴板。

我认为(几乎)不可能实现它。使用 input type=file 对您有帮助吗?还是a drag-drop surface?这对我来说似乎是更好的选择。