With what kind of Exception though, and where is that code being run from? By itself it's fine..
There aren't really any ways around actual trust problems (or they'd be pointless). If you really need full trust, a Windows VPS account might be an option.
The error is coming from the Handler.ashx file. The code is listed below:
<%@ WebHandler Language="VB" Class="Handler" %>
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Image
Imports System.Drawing.Imaging
Public Class Handler
Implements IHttpHandler
'the max size of the thumbnail
Dim PhotoDim As Integer = 192
Dim imagedirectory As String = ""
Dim imagename as String = ""
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
' Set up the response settings
context.Response.ContentType = "image/jpeg"
context.Response.Cache.SetCacheability(HttpCacheability.Public)
context.Response.BufferOutput = False
' Setup the Size Parameter
Dim size As PhotoSize = PhotoSize.Original
Select Case context.Request.QueryString("Size")
Case "S"
size = PhotoSize.Small
Case "M"
size = PhotoSize.Medium
Case "L"
size = PhotoSize.Large
Case Else
size = PhotoSize.Original
End Select
' Setup the PhotoID Parameter
Dim id As Int32 = 1
Dim stream As IO.Stream = Nothing
If ((Not (context.Request.QueryString("PhotoLocation")) Is Nothing) AndAlso (context.Request.QueryString("PhotoLocation") <> "")) Then
Dim path As String = CStr(context.Request.QueryString("PhotoLocation"))
stream = New FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Open, FileAccess.Read, FileShare.Read)
stream = PhotoManager.ResizeImageFile(stream, size)
Else
If ((Not (context.Request.QueryString("PhotoID")) Is Nothing) _
AndAlso (context.Request.QueryString("PhotoID") <> "")) Then
id = [Convert].ToInt32(context.Request.QueryString("PhotoID"))
stream = PhotoManager.GetPhoto(id, size)
Else
id = [Convert].ToInt32(context.Request.QueryString("AlbumID"))
stream = PhotoManager.GetFirstPhoto(id, size)
End If
' Get the photo from the database, if nothing is returned, get the default "placeholder" photo
If (stream Is Nothing) Then
stream = PhotoManager.GetPhoto(size)
End If
End If
' Write image stream to the response stream
Dim buffersize As Integer = (1024 * 16)
Dim buffer() As Byte = New Byte((buffersize) - 1) {}
Dim count As Integer = stream.Read(buffer, 0, buffersize)
Do While (count > 0)
context.Response.OutputStream.Write(buffer, 0, count) <---the error occurs here
count = stream.Read(buffer, 0, buffersize)
Loop
End Sub
End Class
The exception details are below.
System.Security.SecurityException was unhandled by user code
Message="Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
Source="mscorlib"
StackTrace:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Web.HttpWorkerRequest.SendResponseFromMemory(IntPtr data, Int32 length)
at System.Web.HttpWorkerRequest.SendResponseFromMemory(IntPtr data, Int32 length, Boolean isBufferFromUnmanagedPool)
at System.Web.HttpResponseUnmanagedBufferElement.System.Web.IHttpResponseElement.Send(HttpWorkerRequest wr)
at System.Web.HttpWriter.Send(HttpWorkerRequest wr)
at System.Web.HttpResponse.Flush(Boolean finalFlush)
at System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
at System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at Handler.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
troubleshooting tips
use equivalent managed lbraries
when deploying an office solution, check to make sure you have fulfilled all necessary security requirements.
use a certificate to obtain the required permission(s).
If an assembly implementing the custom security object references other assembles, add the referenced assemblies to the full trust assembly list.
Everything seems to indicate it is a security issue. any suggestions?
Thanks Marvin