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.
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=184.108.40.206, 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
- On the Web server, open Administrative Tools, and then double-click Microsoft .NET Framework configuration.
- Expand Runtime Security Policy, expand Machine, and then expand Code Groups.
- Right click All_Code, and then click New.
- Select Create a new code group. Give your code group a relevant name, such as the name of the applications share. Click Next.
- In the Choose the condition type for this group list, select URL.
- 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.
- Click Next. On the next page, select Use an existing permission set, and then select FullTrust.
- Click Next, and then click Finish.
- Restart Microsoft Internet Information Services (IIS) to restart the ASP.NET worker process.
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.