PRB - SecurityException in Medium Trust with Visual Studio Test Web Server
Thursday, 05 May 2011
When testing in Vusual Studio a web page that uses smartDBforms.NET
and displays images from DB the images could not be displayed. Instead of the
image an error icon is displayed.
SYMPTOMS
When testing in Vusual Studio a web page that uses smartDBforms.NET
and displays images from DB the images could not be displayed. Instead of the
image an error icon is displayed.
The following screenshot illustrates the problem:
When the image url is displayed in a separate tab a Security Exception stack
trace is shown:
[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission,
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +58
System.Web.HttpWorkerRequest.SendResponseFromMemory(IntPtr data, Int32 length) +50
System.Web.HttpWorkerRequest.SendResponseFromMemory(IntPtr data, Int32 length, Boolean isBufferFromUnmanagedPool) +13
System.Web.HttpResponseUnmanagedBufferElement.System.Web.IHttpResponseElement.Send(HttpWorkerRequest wr) +34
System.Web.HttpWriter.Send(HttpWorkerRequest wr) +76
System.Web.HttpResponse.Flush(Boolean finalFlush) +1007
System.Web.HttpResponse.Flush() +20
System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size) +8858338
System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count) +100
|
The problem occurs only in the Visual Studio ASP.NET Development Server(Cassini)
with
ASP.NET 2.0
and only in Medium Trust level.
The problem does not occur in ASP.NET 4 or in IIS5, IIS6 and IIS7.
CAUSE
This problem is caused by a bug in the integration of
Visual Studio ASP.NET Development Server and ASP.NET 2.0.
For more details see article
HttpResponse.OutputStream.Write throws SecurityException under partial trust.
RESOLUTION
The problem can be resolved in the following ways:
- Increase the Web site trust level to higher than Medium. In the Web.config file
modify the <trust level="Medium"/> tag.
- Change the Web Site Build Target Framework to .NET 4. Right click on the WebSite
in Solution Explorer. Select "Property Pages"/Build.
APPLIES TO
- Only to ASP.NET 2.0( including .NET 3.0 and .NET 3.5) with combination with
ASP.NET Development Server and only in Medium Trust Level
|