Help with Http Handler

ahmad_hamdan

Member
Joined
May 24, 2010
Messages
19
Programming Experience
Beginner
Hi,

I have this problem with http handler where i can't use the javascript on the page that the handler is associated with, for example the handler writes an image to an aspx page and i have a javascipt that disable the right click on that page when i run the page without the handler the javascript works but when i run it with the handler it stops working

Here are all the codes:
Handler Code:
VB.NET:
 Imports Microsoft.VisualBasic

Imports System.Drawing
Public Class ImageHandler
    Implements IHttpHandler

    Public ReadOnly Property IsReusable As Boolean Implements System.Web.IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
        Dim request As HttpRequest = context.Request
        Dim id = request("id")
        Dim path As String = "D:\" + id + ".jpg"
        Dim i As Image = Image.FromFile(path)
        context.Response.Write("hello")
        context.Response.Clear()
        context.Response.ContentType = "image/jpeg"
        i.Save(context.Response.OutputStream, Imaging.ImageFormat.Jpeg)

    End Sub
End Class

First Page:
VB.NET:
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Button1.Attributes.Add("onclick", "window.open('Image.aspx?id=08052010195','','toolbar=no,location=no')")
    End Sub
End Class

Page associated with handler html Code:
VB.NET:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Image.aspx.vb" Inherits="Image" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
<script language="javascript" type="text/javascript">
<!--

    //Disable right mouse click Script
    //By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
    //For full source code, visit http://www.dynamicdrive.com

    var message = "Function Disabled!";

    ///////////////////////////////////
    function clickIE4() {
        if (event.button == 2) {
            alert(message);
            return false;
        }
    }

    function clickNS4(e) {
        if (document.layers || document.getElementById && !document.all) {
            if (e.which == 2 || e.which == 3) {
                alert(message);
                return false;
            }
        }
    }

    if (document.layers) {
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown = clickNS4;
    }
    else if (document.all && !document.getElementById) {
        document.onmousedown = clickIE4;
    }

    document.oncontextmenu = new Function("alert(message);return false")

// --> 
</script>
    <form id="form1" runat="server">
    <div>
    howdy
    </div>
    </form>
</body>
</html>

Web.config for handler:
VB.NET:
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
	<system.web>
		<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
		<httpHandlers>
			<add verb="*" path="Image.aspx" type="ImageHandler"/>
		</httpHandlers>
	</system.web>
	<system.webServer>
		<handlers>
			<add verb="*" path="Image.aspx" name="ImageHandler" type="ImageHandler" modules="IsapiModule" scriptProcessor="%path%\aspnet_isapi.dll"/>
		</handlers>
	</system.webServer>
</configuration>

I think that handler clears all of that page content because i tried to add some code to debug it but it didn't run in the debugger when i associated the page with the handler

Can anyone help me with it?

Thanks in adavance
 
Back
Top