Click here to Skip to main content
15,888,984 members
Articles / Database Development / SQL Server / SQL Server 2008R2
Tip/Trick

Request for the Permission of Type System.Web.AspNetHostingPermission

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
23 Sep 2014CPOL2 min read 26.4K   4   1
Solved the Permission issue when I hosted my ASP.NET application on IIS7

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

  • 23rd September, 2014: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Mindfire Solutions
India India
Software engineer in Mindfire Solutions.

Comments and Discussions

 
QuestionQuite helpful Pin
NaibedyaKar12-Jan-15 19:36
professionalNaibedyaKar12-Jan-15 19:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.