There are several file handlers my site uses, and they all had repeating code. In an effort to tidy up I created a common base class they can all inherit:
我的网站使用了几个文件处理程序,它们都有重复的代码。为了整理我创建了一个公共基类,他们都可以继承:
Public MustInherit Class HandlerBase
Implements System.Web.IHttpHandler, System.Web.SessionState.IRequiresSessionState
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Public Overridable Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
RequestHandler(context)
End Sub
Protected Overridable Sub RequestHandler(ByVal context As HttpContext)
Select Case context.Request.HttpMethod
Case "GET"
GetFile(context)
Case "POST"
UploadFile(context)
Case "DELETE"
DeleteFile(context)
Case Else
context.Response.ClearHeaders()
context.Response.StatusCode = 405
End Select
End Sub
Protected MustOverride Sub GetFile(ByVal context As HttpContext)
Protected MustOverride Sub UploadFile(ByVal context As HttpContext)
Protected MustOverride Sub DeleteFile(ByVal context As HttpContext)
end class
Two of my handlers work perfectly after inheriting the base class, but one doesn't seem to fire at all. The only difference is that this handler overrides RequestHandler:
我的两个处理程序在继承基类之后工作得很好,但似乎根本没有。唯一的区别是这个处理程序重写了RequestHandler:
Protected Overrides Sub RequestHandler(ByVal context As HttpContext)
Select Case context.Request.HttpMethod
Case "GET"
GetFile(context)
Case Else
context.Response.ClearHeaders()
context.Response.StatusCode = 405
End Select
End Sub
I access the handler and ProcessRequest is never called in base nor RequestHandler
我访问处理程序,并且从不在base或RequestHandler中调用ProcessRequest
1 个解决方案
#1
0
Found this was a small typo after inspecting the request in fiddler:
在fiddler检查请求后发现这是一个小错字:
Protected Overrides Sub DeleteFile(ByVal context As HttpContext
Throw New NotImplementedException()
End Sub
Missing a closing brackets for paramaters. Ill vote to close this.
缺少参数的结束括号。我投票结束这个。
#1
0
Found this was a small typo after inspecting the request in fiddler:
在fiddler检查请求后发现这是一个小错字:
Protected Overrides Sub DeleteFile(ByVal context As HttpContext
Throw New NotImplementedException()
End Sub
Missing a closing brackets for paramaters. Ill vote to close this.
缺少参数的结束括号。我投票结束这个。