在我的解决方案中,我有几个项目。
在我的Allgemein.dll(General.dll)我有一个自定义的httphandler,它寻找pdf并用它做一些事情。
在我的解决方案的每个项目中,我都包含Allgemein.dll。
现在如果我退出我的应用程序并且我打电话给pdf,我的httphandler工作得很好。但是,如果我现在登录我的应用程序并调用pdf,我收到以下错误:“程序集”Allgemein“中的类型”Allgemein.Handlers.FileProtectionHandler“无法加载。”
我做错了什么?
我的web.config
<httpHandlers>
<add path="*.pdf" verb="*" validate="true" type="Allgemein.Handlers.FileProtectionHandler, Allgemein" />
</httpHandlers>
<handlers>
<add name="PDF" path="*.pdf" verb="*" type="Allgemein.Handlers.FileProtectionHandler, Allgemein" resourceType="Unspecified" />
</handlers>
我的FileProtectionHandler.vb
Imports System
Imports System.Web
Imports System.Web.Security
Imports System.IO
Imports System.Web.SessionState
Namespace Allgemein.Handlers
Public Class FileProtectionHandler : Implements IHttpHandler
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Public Sub ProcessRequest(ByVal context As HttpContext)
Select Case context.Request.HttpMethod
Case "GET"
If Not context.User.Identity.IsAuthenticated Then
FormsAuthentication.RedirectToLoginPage()
Return
End If
Dim requestedFile As String = context.Server.MapPath(context.Request.FilePath)
If context.User.IsInRole("User") Then
SendContentTypeAndFile(context, requestedFile)
Else
context.Response.Redirect("~/Portal/Fehler403.aspx")
End If
Exit Select
End Select
End Sub
Private Sub IHttpHandler_ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
Throw New NotImplementedException()
End Sub
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
Dim res As String = Nothing
Dim fileinfo As FileInfo = New FileInfo(filename)
If fileinfo.Exists Then
Select Case fileinfo.Extension.Remove(0, 1).ToLower()
Case "pdf"
res = "application/pdf"
Exit Select
End Select
Return res
End If
Return Nothing
End Function
End Class
End Namespace
在与OP的共同努力之后,已经得出结论,MIR.Web.Allgemein
是根名称空间。
在这种情况下,实际的类型名称是MIR.Web.Allgemein.Allgemein.Handlers.FileProtectionHandler
,它是根名称空间[dot]来自代码[dot]类名的实际名称空间。