Request for the permission of type 'System.Web.AspNetHostingPermission' failed when compiling web site on a Network Share or Intranet Project

10,803

Solution 1

After some additional digging I came across a blog post by Aaron Stebner covering Details about setup for the .NET Framework 2.0 configuration tool. Stebner details how the Configuration Utility was removed from the .NET redistributable and placed only in the SDK. Not a big deal a few years ago but now that the community relies upon newer SDKs and only installs the redistributable / compact versions of the framework we have lost access to the .NET Framework 2.0 Configuration Tool.

The official answer from Microsoft is to Configure Security Policy Using the Code Access Security Policy Tool (Caspol.exe). Unfortunately, this command line utility did not work for me. I however, do not rule out user error as to why it failed.

Ultimately, Stebner solved my issue because he provides an installer for the configuration tool. Which once I had the configuration utility installed allowed me follow the steps outlined in th DotNetSlackers article System.Web.AspNetHostingPermission when Accessing Network or Intranet Projects using Visual Studio 2005 which I have paraphrased into steps below.

To change the local machine's .NET Security Settings goto

Start > Control Panel > Administrative Tools > Microsoft .NET Framework 2.0 Configuration

Fully expand My Computer and select Runtime Security Policy. On the right, choose Adjust Zone Security. Leave the default option (Make changes to this computer) and hit next. Choose Local Intranet and change the trust level to Full Trust. Then choose Next and then Finish. Restart Visual Studio and you should be all set.

Solution 2

Try to change the application pool setting Load User Profile to True.

In Windows 7 it is set to False by default. It seems that in Windows Vista IIS 7 sets this automatically for you.

Share:
10,803
ahsteele
Author by

ahsteele

Professional success influenced by practical academics has shaped my outlook on software development. I have never stopped learning and am always interested in refining my development processes. For me it is not just the programming, all aspects of software development excite me.

Updated on June 09, 2022

Comments

  • ahsteele
    ahsteele almost 2 years

    I have been using Windows 7 for a while but have not had to work with a particular legacy intranet application since my upgrade. Unfortunately, this application is setup as an ASP.NET Website project hosted on an intranet server. When I have the website open in Visual Studio 2008 and try to debug it, I receive the following compiler error:

    Request for the permission of type 'System.Web.AspNetHostingPermission' failed

    To resolve this issue on Windows Vista machines, I would change the machine's .NET Security Configuration trust level to full for the local intranet (fix outlined here). I believe this configuration utility relied upon the mscorcfg.msc which from some cursory research appears to be apart of the .NET 2.0 SDK. I have tried to follow the instructions from this Microsoft Support article running the command below to no avail.

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

    Presently, I have the following .NET, ASP.NET, and .NET SDK components installed on my machine

    • Microsoft .NET Compact Framework 2.0 SP2
    • Microsoft .NET Compact Framework 3.5
    • Microsoft .NET Framework 4 Client Profile
    • Microsoft .NET Framework 4 Extended
    • Microsoft .NET Framework 4 Multi-Targeting Pack
    • Microsoft ASP.NET MVC 1.0
    • Microsoft ASP.NET MVC 2
    • Microsoft ASP.NET MVC 2 - Visual Studio 2008 Tools
    • Microsoft ASP.NET MVC 2 - Visual Studio 2010 Tools
    • Microsoft Windows SDK for Visual Studio 2008 .NET Framework Tools - enu
    • Microsoft Windows SDK for Visual Studio 2008 Headers and Libraries
    • Microsoft Windows SDK for Visual Studio 2008 SDK Reference Assemblies and IntelliSense
    • Microsoft Windows SDK for Visual Studio 2008 SP1 Tools
    • Microsoft Windows SDK for Visual Studio 2008 SP1 Win32 Tools
    • Microsoft Windows SDK for Windows Server 2008 (6001.18000.367)

    Do I need to install the .NET 2.0 SDK? Am I issuing the caspol command incorrectly? Is there something else that I am missing?