asp.net – 自定义HttpHandler错误:无法加载类型’FileProtecti
发布时间:2020-12-16 07:36:39 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试实现一个自定义HttpHandler(第一次),我已经得到了一个教程,但无法让它工作.然后我找到了另一个教程,但无法让它工作,他们都给了我相同的错误信息. 自定义处理程序是为了保护人们不要下载某些文件类型,虽然我认为错误是一些配置问题,因为一旦我将htt
我正在尝试实现一个自定义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 解决方法
我有类似的问题.解决方案在属性中定义的根命名空间中.
在我的代码中我没有命名空间,所以在这种情况下你需要使用 type="[namespace or root namespace].[your class name]" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 用于bower.json文件的Visual Studio 2015 RC上的
- MVC .Net Cascade在使用EF Code First Approach时删除
- 如何获得干净的ASP.Net错误页面?
- asp.net-mvc-3 – 从单控制器操作返回多个部分视图?
- asp.net-mvc – 错误处理在asp.net mvc 3
- asp.net-mvc – Moq的意外验证行为
- asp.net-mvc – 在asp身份声明和会话数据之间进行选择
- asp.net – 当用户按下文本框中的返回时,我可以取消回发吗?
- asp.net – AttachDbFilename的问题是什么
- 从ASP.NET连接到远程MongoDB实例