API ASP.NET de GrabzIt prend également en charge les événements. Vous trouverez ci-dessous un exemple d’affectation d’un gestionnaire au ScreenShotComplete
événement avant que la capture d'écran est appelée. Puis, une fois la capture d'écran complétée, le code dans le grabzIt_ScreenShotComplete
méthode est appelée.
private GrabzItClient grabzIt = GrabzItClient.Create("Sign in to view your Application Key", "Sign in to view your Application Secret")%>"); protected void btnSubmit_Click(object sender, EventArgs e) { grabzIt.ScreenShotComplete += grabzIt_ScreenShotComplete; grabzIt.URLToImage("https://www.tesla.com"); //The below line specifies the GrabzIt.ashx handler inside the GrabzIt.dll grabzIt.Save(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "GrabzIt.ashx"); } //The event method saves the screenshot protected void grabzIt_ScreenShotComplete(object sender, ScreenShotEventArgs result) { GrabzItFile file = grabzIt.GetResult(result.ID); file.Save(Server.MapPath("~/results/"+result.Filename)); }
Enfin, configurez le fichier web.config pour que le fichier GrabzIt.ashxints au maître intégré dans le DLL GrabzIt. Si cela n’est pas fait correctement, le ScreenShotComplete
événement ne sera pas tiré.
Rappelez-vous ceci rappeler ne fonctionnera pas si votre application est située sur localhost.
<httpHandlers> <add verb="*" path="GrabzIt.ashx" type="GrabzIt.Handler, GrabzIt" /> </httpHandlers>