How to identify offending full trust asp.net code in a medium trust environment
<p>We are deploying our MVC3 C# web application to a new hosting environment. The environment we came from allowed full trust applications levels. The new hosting environment only allows medium trust, thus our application is now throwing security errors for calls requiring full trust. We have been reviewing our code trying to find the offending calls so we can work around the trust issues but have been unsuccessful in finding the specific lines of code. Below is the exception we are getting which is quite vague to the origin of the call:</p>

<p><strong>Security Exception</strong><br><br>
<strong>Description:</strong> The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. </p>

<p><strong>Exception Details:</strong> System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.</p>

<p><strong>Source Error:</strong><br>
An unhandled exception was generated during the execution of the current web<br>
request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</p>

<p><strong>Stack Trace:</strong> </p>

<pre><code>[SecurityException: Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0,      
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark&amp;  
stackMark,      
Boolean isPermSet) +0
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap,
StackCrawlMark&amp;  
stackMark) +31
System.Security.CodeAccessPermission.Demand() +46
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, 
Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options,
SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath,
Boolean checkHost) +654
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare
share) +65
System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForRead(String  
streamName) +85
System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.
IInternalCon    figHost.OpenStreamForRead(String streamName, Boolean assertPermissions)    
+116
System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.
IInternalCon figHost.OpenStreamForRead(String streamName) +10
System.Configuration.Internal.DelegatingConfigHost.OpenStreamForRead(String streamName)
+11
System.Configuration.UpdateConfigHost.OpenStreamForRead(String streamName) +38
System.Configuration.BaseConfigurationRecord.InitConfigFromFile() +319
</code></pre>

<p>We were wondering if anyone can give us some insight on one how to track down this security level error. Is there any type of application or plugin that can assist us in determining the location of the issue? Second can anyone shed light on when these exceptions are thrown? Does the offending code have to be called to throw the exception or does this error occur when the page is being compiled on the web server?</p>
