在ASP.NET中获取屏幕截图时出现“句柄无效”错误

hm

当客户端用户单击按钮时,我尝试获取客户端用户的屏幕截图。

该代码在本地计算机上有效。但是,当我在服务器上发布时,该代码无效。我收到“句柄无效”错误。

我的错误在哪里?

using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing;

public partial class Page: System.Web.UI.Page

{
    protected void Page_Load(object sender, EventArgs e) {...}

}

static string ImagePath;
public static void ScreenShot()
{


 foreach (Screen screen in Screen.AllScreens)
        {
            Bitmap bitmap = new Bitmap(screen.Bounds.Width, screen.Bounds.Height, PixelFormat.Format32bppArgb);

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.CopyFromScreen(screen.Bounds.X, screen.Bounds.Y, 0, 0, screen.Bounds.Size, CopyPixelOperation.SourceCopy);
            }

            ImagePath= "/Screenshots/" + HttpContext.Current.Session["UserName"].ToString()+ " "+ DateTime.Now.ToString("dd.MM.yyyy HH.mm.ss");
            bitmap.Save(HttpContext.Current.Server.MapPath(ImagePath+ ".jpg"));
        }

}

   protected void btn_Click(object sender, EventArgs e)
   {
     ScreenShot(); 
   }
帕特里克·霍夫曼

您不能使用Screens该类,因为ASP.NET不在桌面交互模式下运行。您无法从用户或服务器从ASP.NET中的代码访问屏幕。

您应恢复为最佳,以客户端的JavaScript来得到当前网页的屏幕截图。那是你所能做的最好的。(请不要参加ActiveX导览)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在asp.net中获取当前页面的屏幕截图。

使用 asp.net 时指定的强制转换无效错误?

ASP.NET Core:获取外键时出现NullReferenceException

选择EnableEventValidation时出现ASP.NET Dropdownlist错误

Asp.net呈现某些样式时出现错误

ASP.net中的错误:BC30037:字符无效

asp.net页面中的无效viewstate错误

在ASP .NET CORE / MVC 6应用程序中设置Swagger时出现500错误

在 asp.net mvc Core 2.1 中调用 POST 方法时出现错误 404

ASP.NET MVC 4自定义句柄错误

在ASP.NET MVC中添加BaseController会出现错误

在asp.net中从SQL检索数据时获取错误的日期格式

发送屏幕截图时出现错误

从Asp.net Core 2.0升级到2.1后出现“无效的列名”错误

使用asp.net c#代码增加WebBrowser的高度,然后出现错误:参数无效

ASP.Net MVC中的演练屏幕

当我在Asp.net Core(MVC)中搭建控制器时,出现代码生成错误

尝试在ASP.Net Core 2.2 API中实现UseNetTopologySuite时,为什么会出现此错误?

在IIS 8.5中的asp.net mvc 5上使用后期处理时出现错误404

在 asp.net core web api 控制器中读取表单数据时出现 405 http 错误

在ASP.NET MVC中请求URL时获取404

如何在 ASP.NET 5 路由中传递无效值时获取验证消息

从 jquery ajax 调用 API 控制器 ASP.net Core 时出现错误请求错误

在ASP.NET Web窗体内使用ASP.NET Web API时出现“方法不允许”错误

Javascript电子邮件验证错误(在ASP.Net中有效,而在ASP.Net MVC中无效)

运行 .NET 5 ASP.NET MVC Web App 时出现 NETSDK1004 错误

如何截取 div 的屏幕截图并将值插入模型的属性 ASP .NET Core

将Windows窗体屏幕截图应用程序转换为ASP.NET

从Gridview更新时的ASP.NET错误