Open in new window

Social Icons

Friday, August 31, 2012

Visual Studio ASP.NET Network Share Security Exception Error

If you have your net code on a network share you probably will receive a security exception error when debugging it on your local development server.

 

When you use a virtual directory that points to a remote share to host a Microsoft ASP.NET-based application, you may receive an error message that is similar to:

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.

http://support.microsoft.com/kb/320268

 

To resolve this you need to use the Windows caspol.exe command to assign FullTrust to the share.

 

Run the following commands from an elevated cmd prompt on any client computers you’re running Visual Studio on or just place the commands in a cmd or bat file and Run as Administrator (right-click). REPLACE “\\SERVER\Data\” with the network path to your .Net files.

 

C:\Windows\Microsoft.NET\Framework\v2.0.50727\CasPol.exe -q -m -ag 1 -url "file:////\\SERVER\Data\*" FullTrust -exclusive on

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CasPol.exe -q -m -ag 1 -url "file:////\\SERVER\Data\*" FullTrust -exclusive on

C:\Windows\Microsoft.NET\Framework\v4.0.30319\CasPol.exe -q -m -ag 1 -url "file:////\\SERVER\Data\*" FullTrust -exclusive on

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\CasPol.exe -q -m -ag 1 -url "file:////\\SERVER\Data\*" FullTrust -exclusive on

 

The first two commands set full trust for net 2.0, 3.0 & 3.5 for 32bit & 64bit machines.

The second two commands set full trust for net 4.0 4.5 for 32bit & 64bit machines.

 

If you want to reset the trust level to the defaults use the following commands:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\CasPol -quiet -machine -reset

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CasPol -quiet -machine -reset

C:\Windows\Microsoft.NET\Framework\v4.0.30319\CasPol -quiet -machine -reset

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\CasPol -quiet -machine –reset

 

VS Net FullTrust on a Network Share
read more