HttpHandler

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




Hi,

I have a problem of page redirection. Basically, the user has to connect to
the local web server, but some pages need to be served by a remote server,
because it contains some confidential data that cannot be moved locally
(everything occurs in the company Intranet, however). Since the ASP.NET
application uses extensive Javascript, we cannot make it work because of the
"cross-site" (same origin policy) of Javascript.

Therefore, we thought it would be useful to implement the IHttpHandler and
create a request for all pages that need to be served remotely. The code is
the following:

*************
Public Class AsyncProxyHandler
Implements IHttpHandler, IRequiresSessionState

Public Sub ProcessRequest(ByVal context As HttpContext) Implements
IHttpHandler.ProcessRequest

Dim url As String = context.Request.RawUrl
url = url.Replace(context.Request.ApplicationPath, "")
Dim request As HttpWebRequest
request =
DirectCast(WebRequest.Create("http://localhost/AsyncProxy2/Default.aspx";),
HttpWebRequest)
request.Credentials = CredentialCache.DefaultCredentials

Try
Dim response As HttpWebResponse =
DirectCast(request.GetResponse(), HttpWebResponse)
Dim responseStream As Stream = response.GetResponseStream()
Dim output As Stream = context.Response.OutputStream
CopyStream(responseStream, output)

Catch we As System.Net.WebException

End Try

End Sub

Private Sub CopyStream(ByVal fromStream As Stream, ByVal toStream As
Stream)
Try
Dim sr As New StreamReader(fromStream)
Dim sw As New StreamWriter(toStream)
sw.WriteLine(sr.ReadToEnd())
sw.Flush()
Catch ex As Exception
End Try
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.IsReusable

Get
Return True
End Get

End Property

End Class
*************

However, since the same page also contains controls, all the events (button
click events, for instance) are never executed. We also tried we a dummy
application, and everything we can see on the page is the content of the
page included in the request, no other control.

Are we doing something wrong? Is there a better solution to overcome our
problem?

Any help would be appreciated. We are working on this problem for several
days, but we cannot find a solution....

Thanks
Mike





.


Quantcast