gpt4 book ai didi

asp.net - 自定义 HttpHandler 错误 : Could not load type 'FileProtectionHandler'

转载 作者:行者123 更新时间:2023-12-03 18:15:10 27 4
gpt4 key购买 nike

我正在尝试实现一个自定义 HttpHandler(第一次),我已经获得了一个教程,但无法让它工作。然后我找到了另一个教程,但无法使其正常工作,它们都给了我相同的错误消息。

自定义处理程序是为了保护人们免于下载某些文件类型,尽管我认为该错误是某种配置问题,因为一旦我将 httpHandlers 添加到 Web.Config 文件中,我就无法让网站正常工作。

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load type 'FileProtectionHandler'.

Source Error:

Line 47: </compilation>
Line 48: <httpHandlers>
Line 49: <add verb="*" path="*.pdf" type="FileProtectionHandler"/>
Line 50: </httpHandlers>

如果您需要更多代码,请告诉我。

谢谢你的帮助。 J。
    <%@ WebHandler Language="VB" Class="FileProtectionHandler" %>

Imports System
Imports System.Web
Imports System.Web.Security
Imports System.IO
Imports System.Web.SessionState

Public Class FileProtectionHandler : Implements IHttpHandler

Private Function SendContentTypeAndFile(ByVal context As HttpContext, ByVal strFile As [String]) As HttpContext
context.Response.ContentType = GetContentType(strFile)
context.Response.TransmitFile(strFile)
context.Response.[End]()
Return context
End Function

Private Function GetContentType(ByVal filename As String) As String
' used to set the encoding for the reponse stream
Dim res As String = Nothing
Dim fileinfo As New FileInfo(filename)

If fileinfo.Exists Then
Select Case fileinfo.Extension.Remove(0, 1).ToLower()
Case "pdf"
If True Then
res = "application/pdf"
Exit Select
End If
End Select

Return res
End If

Return Nothing
End Function

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/plain"
context.Response.Write("Hello World")
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class

Property Pages Img

最佳答案

我有类似的问题。解决方案是在属性中定义的根命名空间中。
在我的代码中我没有命名空间,所以在这种情况下你需要使用

type="[namespace or root namespace].[your class name]"

关于asp.net - 自定义 HttpHandler 错误 : Could not load type 'FileProtectionHandler' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6533709/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com