"System.Security.SecurityException: Security error" error message when the virtual directory points to a remote share in ASP.NET

Very recently I have faced a problem when hosting a web application in hosting server. This application is running perfectly on local PC but security exceptions occurs when hosting to a server.

I have got the following error message:

Security Exception Description: 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.

Exception Details: System.Security.SecurityException: Security error.

After consult with senior guys they refer the solution which is sharing with you.

Main Cause

The System.Web namespace does not have the AllowPartiallyTrustedCallersAttribute applied to it.

Any code that is not in the My_Computer_Zone code group that does not have this attribute requires the FullTrust user right. Therefore, the remote share that holds the Web applications content requires FullTrust.


To resolve this behavior, grant the FullTrust right to the remote share:

1.On the Web server, open Administrative Tools, and then double-click Microsoft .NET Framework Configuration.
2.Expand Runtime Security Policy, expand Machine, and then expand Code Groups.
3.Right-click All_Code, and then click New.
4.Select Create a new code group. Give your code group a relevant name, such as the name of the applications share. Click Next.
5.In the Choose the condition type for this code group list, select URL.
6.In the URL box, type the path of the share in the following format:
7.Note Replace computername with the name of the computer that is hosting the remote share. Replace sharename with the name of the share.
8.Click Next. On the next page, select Use an existing permission set, and then select FullTrust.
9.Click Next, and then click Finish.

Restart Microsoft Internet Information Services (IIS) to restart the ASP.NET worker process.

If Microsoft .NET Framework Configuration is not displayed under Administrative Tools, you can install the .NET Framework SDK to add Microsoft .NET Framework Configuration.

Alternatively, you can run the following command to make the change:

Drive:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\caspol.exe -m -ag 1 -url "file:////\\computername\sharename\*" FullTrust -exclusive on


Popular posts from this blog

How can I get a value of a property from an anonymous type (C#)

The model backing the 'MyDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

"This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet."