in my solution i have a couple of projects.
At my Allgemein.dll (General.dll) i have a custom httphandler which looks for pdf's and does something with it.
At every project in my solution i include the Allgemein.dll.
Now if i'm logged out of my application and i call a pdf, my httphandler works great. But if i'm now login to my application and call a pdf, i got the following error: "The type "Allgemein.Handlers.FileProtectionHandler" in the assembly "Allgemein" could not be loaded."
What i'm doing wrong?
My 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>
My 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
After a joined effort with the OP it has been concluded that the MIR.Web.Allgemein
is the root namespace.
In this case, the actual type name would be MIR.Web.Allgemein.Allgemein.Handlers.FileProtectionHandler
which is the root namespace [dot] the actual namespace from code [dot] class name.