R
Random
I'm using a set of HttpHandlers in my site to parse out the path and write
content based on information in that path, including the querystring.
Rather than have multiple entries in the web.config file, I thought I'd
instead create an HttpHandlerFactory that would analyze the path information
and then hand over the rest of the content generation to a specific
HttpHandler. My code is something like this...
Public Class ExportHandlerFactory
Implements IHttpHandlerFactory
Public Function GetHandler(ByVal context As HttpContext, ByVal
requestType As String, ByVal url As String, ByVal pathTranslated As String)
As IHttpHandler
Implements GetHandler
Select Case Path.GetFileNameWithoutExtension(url).ToLower()
Case "path-a"
Return New aPathHttpHandler
Case "path-b"
Return New bPathHttpHandler
Case Else
Return
PageParser.GetCompiledPageInstance("~/default.aspx",
context.Server.MapPath("~/default.aspx"), context)
End Select
End Function
Public Sub ReleaseHandler(ByVal handler As System.Web.IHttpHandler)
Implements System.Web.IHttpHandlerFactory.ReleaseHandler
End Sub
End Class
aPathHttpHandler and bPathHttpHandler are both handlers in the App_Code
directory. The problem with this approach is that aPathHttpHandler and
bPathHttpHander then have no querystring to read to analyze for creating
their content to write to the context.Response.
I've thought about just analyzing the querystring in the HttpHandlerFactory
and writing the querystring values to the context.Items collection, but I
want my HttpHandlers to be able to be standalone classes that won't depend
on the HttpHandlerFactory to do this.
Any inspiration or nuggets of wisdom on this would be appreciated.
content based on information in that path, including the querystring.
Rather than have multiple entries in the web.config file, I thought I'd
instead create an HttpHandlerFactory that would analyze the path information
and then hand over the rest of the content generation to a specific
HttpHandler. My code is something like this...
Public Class ExportHandlerFactory
Implements IHttpHandlerFactory
Public Function GetHandler(ByVal context As HttpContext, ByVal
requestType As String, ByVal url As String, ByVal pathTranslated As String)
As IHttpHandler
Implements GetHandler
Select Case Path.GetFileNameWithoutExtension(url).ToLower()
Case "path-a"
Return New aPathHttpHandler
Case "path-b"
Return New bPathHttpHandler
Case Else
Return
PageParser.GetCompiledPageInstance("~/default.aspx",
context.Server.MapPath("~/default.aspx"), context)
End Select
End Function
Public Sub ReleaseHandler(ByVal handler As System.Web.IHttpHandler)
Implements System.Web.IHttpHandlerFactory.ReleaseHandler
End Sub
End Class
aPathHttpHandler and bPathHttpHandler are both handlers in the App_Code
directory. The problem with this approach is that aPathHttpHandler and
bPathHttpHander then have no querystring to read to analyze for creating
their content to write to the context.Response.
I've thought about just analyzing the querystring in the HttpHandlerFactory
and writing the querystring values to the context.Items collection, but I
want my HttpHandlers to be able to be standalone classes that won't depend
on the HttpHandlerFactory to do this.
Any inspiration or nuggets of wisdom on this would be appreciated.