System.Security.SecurityException in Asp.Net

| April 23, 2013 | 0 Comments

I was trying to host Intranet website based on .Net Framework 2.0 on remote share with fewer privileges. But the web application got failed and showed exception as :

Server Error in ‘/rso/intranet’ Application.

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: Request for the permission of type ‘System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.

Then I researched about same and reached to conclusive reason.

Cause of Exception:

The actual reason behind the exception is that assemblies (.dll) in Bin folder have fewer privileges than other assembly. 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.

Solution for System.Security.SecurityException

  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 group list, select URL.
  6. In the URL box, type the path of the share in the following format: file:////\\computername\sharename\*  In our case it was as : file:////10.23.46.34/rso/intranet/*Note: Replace computername with the name of the computer that is hosting the remote share. Replace sharename with the name of the share.
  7. Click Next. On the next page, select Use an existing permission set, and then select FullTrust.
  8. Click Next, and then click Finish.
  9. Restart Microsoft Internet Information Services (IIS) to restart the ASP.NET worker process.

Alternate Solution

Run following command:

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

where Drive is the root folder for Windows.

Hope this help anyone trying to get rid of hosting permission error which brings on yellow page with big message, “System.Security.SecurityExceptioin”. If you have any other solution do share with us.

Category: Asp.Net, Error and Solution

Leave a Reply

%d bloggers like this: