Introduction
This piece of solution worked for me to resolve the permission issue of type '
System.Web.AspNetHostingPermission
' (Server Error in '/' Application) when hosting an ASP.NET application in IIS7. Generally, this is generic type of error that we face when we host our ASP.NET application in IIS web server. But here, I have provided some more information about the error and the exact solution to resolve the problem.
Using the Code
Let's start the description about the problem and a solution for it.
I have built a web application in VS 2012 by using the ASP.NET technology with C# language and backend as a SQL server 2008. When I run my application in .NET platform (Visual Studio), it works fine for me. So to access the application globally, I just publish the web application and host the application with all configuraton settings in IIS7. After that, when I tried to access the web pages, I got an error like:
Server Error in '/' 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.
Source Error
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace
[SecurityException: Request for the permission of type
'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.] System.Reflection.Assembly._GetType
(String name, Boolean throw , Boolean ignoreCase) +0 System.Web.UI.Util.GetTypeFromAssemblies(ICollection assemblies,
String typeName, Boolean ignoreCase) +201 System.Web.UI.TemplateParser.GetType
(String typeName, Boolean ignoreCase, Boolean throw ) +323 System.Web.UI.TemplateParser.ProcessInheritsAttribute
(String baseTypeName, String codeFileBaseTypeName,
String src, Assembly assembly) +10891548 System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes
(IDictionary parseData) +365
Version Information
: Microsoft .NET Framework Version:2.0.50727.5456; ASP.NET Version:2.0.50727.545
These were my error details that I explained above. After getting this error for test, I also gave account "
everyone
" user full rights but still I got the same error.
So after a long time strugling with this issue, I just got the solution in IIS apllication pool attribute. Here's my solution.
Solution:
Found the solution by setting the application pool attribute
Load UserProfile = TRUE
What happens if we load
UserProfile = "True"
in an application pool, Windows Cryptographic Service Provider was trying to store or load a key for your certificate in the user store, and since a profile was not available, a cryptographic context was not available. Note that the Load User Profile setting only applies to user accounts.
When the user profile is loaded, this includes their cryptographic store, environment variables such as
%TEMP%
, and other ones. What it eventually boils down to is
LoadUserProfile
called by IIS when the
AppPool
starts.
To know more about application pool "Load user profile" attribute, please check this link "
http://www.iis.net/learn/manage/configuring-security/application-pool-identities
".
Hope it will help. Rock !!!
Points of Interest
Eager to know some new things.
History
-
23
rd
September, 2014: Initial version