In this article I will explain how to resolve the error System.Security.SecurityException: That assembly does not allow partially trusted callers. We have checked on forums many users experience this problems when host their ASP.NET site on shared hosting environment
This is being caused by the security level that your application is being forced to run under. Most commercial shared hosting operations lock down the server space to stop your code from doing anything that may interfere with other sites or the server itself.
This security level is known as the trust level in .NET and it can be set to one of the following values:
- Full trust – your code can do anything that the account running it can do.
- High trust – same as above except your code cannot call into unmanaged code. i.e. Win32 APIs, COM interop.
- Medium trust – same as above except your code cannot see any part of the file system except its application directory. This is the most common trust level that is used in shared hosting environments.
- Low trust – same as above except your code cannot make any out-of-process calls. i.e. calls to a database, network, etc.
- Minimal trust – code is restricted from anything but the most trival processing (calculating algorithms).
Medium trust is the level most commonly used by shared hosting environments and it places severe restrictions on what your code can do – i.e. you cannot call unmanaged code, such as Win32 APIs and COM components and you cannot do anything with the file system or system registry.
Medium trust also prevents your assemblies from running unless they are marked with a strong name and installed into the server’s Global Assembly Cache (GAC). However, this becomes a problem in a hosted environment where you have no direct access to the GAC.
How is the Solution?
To ensure that your assemblies will work in a medium trusted environment, you need to give them a strong name and mark them with an attribute that tells the .NET security runtime to allow the code.
To allow partially trusted callers from your code, add the following attribute to the assembly’s AssemblyInfo.cs file:
[assembly: AllowPartiallyTrustedCallers]
You will also need to ensure that the file references the System.Security namespace.
In addition, you will also need to give your assembly a strong name by signing the assembly though the project properties dialog. An explanation of how to do this can be found here: http://msdn.microsoft.com/en-us/library/ms247123(VS.80).aspx.
Limitations and exceptions
You will have to be careful what assemblies in the .NET framework that you use in partially trusted assemblies, as a number of them cannot be called from partially trusted code. This includes pretty much anything that could be regarded as a major security risk, i,e, access to the file system, event log and system settings.
For example, if you have incorporated logging functionality that uses System.Diagnotics to write to the event log, you will always get a Security Exception when you try to run this code as a partially trusted caller. This is because this is one of the assemblies that requires a higher level of trust before they can be used.
This can be quite a limitation on your application – the full list of assemblies that cannot be called by partially trusted callers can be found here: http://msdn.microsoft.com/en-us/library/aa302328.aspx.
Other Solution – Find ASP.NET Hosting Provider that Support Full Trust
Since your site requires full trust to run, then you must find the hosting provider that also allow Full Trust permission on their hosting environment. We have reviewed so many ASP.NET hosting providers that offer Full Trust. Here are several recommendations from us if you need Full Trust ASP.NET Hosting:
Best US ASP.NET Full Trust Hosting Provider – ASPHostPortal
Since 2008, ASPHostPortal has been growing into one of the best cheap ASP.NET hosting provider that offer affordable ASP.NET hosting provider. They offer top quality and the latest ASP.NET hosting on their ASP.NET hosting environment.
ASPHostPortal is the #1 ASP.NET web hosting company according to us and millions users. ASPHostPortal is one of top recommended Windows ASP.NET Hosting provider, they provide reliable and cheap ASP.NET Full Trust hosting and they have huge support, you can easily contact them anytime you want.
ASPHostPortal has various ASP.NET Full Trust shared hosting plan which start from with an affordable price. There are 4 favorite ASP.NET hosting plans which start from Host One, Host Two, Host Three, and Host Four. Host One plan start with $5.00/month. Host Two start with $9.00/month, Host Three is the most favorite plan start from $14.00/month and Host Four start with $23.00/month. All of their ASP.NET hosting plan allows user host unlimited domains, unlimited email accounts, at least 1 MSSQL and 1 MySQL database.
For more information, please visit their site at http://www.asphostportal.com.
Cheap ASP.NET Full Trust Hosting in Europe – HostForLIFEASP.NET
Founded in 2008 and since then they have grown into one of the largest windows hosting companies in the Europe. HostForLIFEASP.NET is operated from their registered office based in Manchester. Previously, they only have data centers in UK and Amsterdam. Since their business growing very fast, they spread their wings to other country. They have opened 5 data centers within 5 years, it is Frankfurt, Milan, Paris, Seattle and Dallas.
Many developers trusted them due to reliable servers, excellent customer support and a wide range of features. The company was voted as best hosting providers by readers of the then popular magazines in UK and Netherlands. HostForLIFEASP.NET was the recipient of the “Golden European ASP.NET Hosting Services” award from Dev Pro Magazine.
HostForLIFEASP.NET has been recognized as a Microsoft Spotlight Hosting partner. They are also licensed under the Microsoft’s Service Provider Licensing Agreement (SPLA) Program. The company also received several awards from leading developer magazines and online portals.
HostForLIFEASP.NET have a wide range of ASP.NET Full Trust hosting plans like other hosting providers. The company provides unlimited disk space and bandwith on all their hosting plan. The company provides free setup, offers 30 day money back guarantee with instant account activation.
HostForLIFEASP.NET also provides the latest technologies on their Windows ASP.NET hosting environment, such as Windows 2012, latest MSSQL database version, WebSocket, URL Rewrite, etc. The company maintains state of the art data centers in UK, US, Paris, Frankfurt, Amsterdam, and Milan powered with Dell servers.
Here is brief information about their ASP.NET hosting plan and pricing
Reliable ASP.NET Full Trust Hosting United Kingdom – UKWindowsHostASP.NET
If you’re based in UK and looking for ASP.NET hosting that support Full Trust, then UKWindowsHostASP.NET is a good choice.
This company utilizes many datacenters in Europe, but they are focusing on London data center. They have redundant resources to support UKWindowsHostASP.NET servers. Note that UKWindowsHostASP.NET purchases servers only from Dell.
All their data center utilizes the latest technologies and the support of robust facilities and infrastructures, its data center are powerful guarantee for the good performance of UKWindowsHostASP.NET ASP.NET Full Trust hosting.
We have monitored the websites that hosted on their data center and collected relevant statistics during test period. The result shows that UKWindowsHostASP.NET ASP.NET hosting performs surprisingly well both in speed and stability. The average response time of its servers is within 200 ms. The company constantly invests on facilities so now even at traffic peaks the loading speed of websites is at the top level.
In terms of refund policy, the company commits to giving all hosting fees back to the customer who is not completely content with the service received. The full money-back guarantee is applicable to the first 30 calendar days of the term. No Hidden Fees is also promised.
[crp]