So I had this good idea that I would use an HTTPHandler to for our multi file upload project. I have a Java Applet that allows the user to drag and drop or select from a dialog multiple files to upload.
Before I tried to integrate any of this into the main project, I created a proof-of-concept to test with and had no problem with it.
I have a HTTPHandler that implements the System.Web.SessionState.IRequiresSessionState interface which insures I get the session and all was well in my proof-of-concept project. When I moved it, I had to add the functionality that I thought would work without any modifications, but I could not have been more wrong.
First of all, the applet has some sort of java based browser that renders html. This browser apparently starts a new session with the web server so I had to post my session variables in URL parameters (not too big a deal). Then, I tried to implement some code that worked just fine on our single file upload aspx page and suddenly I was in trouble.
The code used COM components from the old ASP days and worked just fine on a WebForm with the ASPCompat page directive set to "true". But HTTPHandlers have no page directives and do not support ASPCompat, so now what?
Solution:
Well after a lot of searching I came across the following article that helped me out: http://www.epocalipse.com/blog/2006/03/04/aspnet-web-services-and-sta-com-objects/
Basically I implemented the System.Web.IHttpAsyncHandler and inherited the System.Web.UI.Page. Then I added the following functions:
Public Function BeginProcessRequest(ByVal context As System.Web.HttpContext, ByVal cb As System.AsyncCallback, ByVal extraData As Object) As System.IAsyncResult Implements System.Web.IHttpAsyncHandler.BeginProcessRequest
Return AspCompatBeginProcessRequest(context, cb, extraData)
End Function
Public Sub EndProcessRequest(ByVal result As System.IAsyncResult) Implements System.Web.IHttpAsyncHandler.EndProcessRequest
AspCompatEndProcessRequest(result)
End Sub
Private Sub FileUpload_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
'The code that used to be in ProcessRequest goes here
End Sub
Now I know what you are thinking. Hey what's up? Why use a HTTPHandler if you are just going to inherit System.Web.UI.Page anyway? Why not just use a webform?
Well, the problem is that I needed a quick fix so that I could move on. This allows me to run STA COM components in my HTTPHandler and hey, I still have a little more control than if this was a webform. And I am able to auto generate a config file used by my Java applet, that is hard coded in the applet (the applet uses a file called thinupload.properties and I wanted to auto generate that file, this allows me to handle .properties files and create the config file on the fly).
No comments:
Post a Comment