API ASP.NET di GrabzIt supporta anche eventi, di seguito è riportato un esempio di assegnazione di un gestore a ScreenShotComplete
evento prima che venga chiamato lo screenshot. Quindi, una volta completato lo screenshot, il codice all'interno di grabzIt_ScreenShotComplete
viene chiamato metodo.
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)); }
Infine, configura web.config in modo che GrabzIt.ashx points al Handler incorporato nel GrabzIt DLL. Se ciò non viene eseguito correttamente, il ScreenShotComplete
l'evento non verrà generato.
Ricorda questo richiama non funzionerà se l'applicazione si trova su localhost.
<httpHandlers> <add verb="*" path="GrabzIt.ashx" type="GrabzIt.Handler, GrabzIt" /> </httpHandlers>