Last post Sep 09, 2015 07:26 PM by MatthewDaver
Aug 20, 2010 12:55 AM|alan.price|LINK
I've struggled with the error "Request for the permission of type System.Web.AspNetHostingPermission failed" twice now and have spent several hours both times trying to solve it. I'm posting the info I found here in hopes that it will save time for others
AND to hopefully get some more recent postings on Google's PageRank.
If you're having the System.Web.AspNetHostingPermission problem, frequently paired with the AJAX Control Toolkit, the fix (at least for me...your results may vary, but I hope they don't) is quite simple. By now you've probably seen plenty of references
to CasPol and how you can run a command to fix your problems. What those posts tend to leave out are software specs and how exactly to run CasPol.
First, I had this issue on two clients with two different IIS servers. Both clients were running Visual Studio 2008 (or Visual Web Developer 2008). One server was running Window Server 2003 (IIS 6) and one was a laptop with Windows 7 64-bit (IIS 7.5).
The problem only occurred after moving the website from the local client to the web server for testing and production. Visual Studio didn't trust the network share (UNC path) location, so it couldn't compile the website or load the AJAX Control Toolkit properly.
So after trying all sorts of trust configurations, I figured it out.
In order to solve the "Request for the permission of type System.Web.AspNetHostingPermission failed" problem (again, in my case and hopefully in yours), you need to run CasPol
on the computer running Visual Studio. That is, don't run CasPol on the server, but on the client. The command (at an elevated command prompt, of course) is
C:\Windows\Microsoft.NET\Framework\v2.0.50727\caspol.exe -m -ag 1 -url "file:////\\computername\sharename\*" FullTrust
If you're on a 64-bit system, make sure to ALSO run
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\caspol.exe -m -ag 1 -url "file:////\\computername\sharename\*" FullTrust
I really hope that this post helps somebody out. And that I can find it again when I forget the solution next time I run into this...
Visual Studio 2008
Visual Web Developer Express 2008
Nov 02, 2010 08:28 AM|Mack73|LINK
Thank you very much. You are right, there are hints but not many resolutions with this clarity and detail out there.
Nov 15, 2010 08:29 PM|StanMarsh|LINK
I tried this option on my development box. It didn't work
I host the site locally by adding a virtual directory to IIS\Default Web Site, then covert the folder to an application in IIS.
The path of "\computername\sharename\" I used is the path of the source code folder that contains the ASP.NET website.
Can anyone help?
Nov 15, 2010 08:41 PM|alan.price|LINK
Is the path you're using more like file:////\\C:\wwwroot\yourlocalfolder or file:////\\localPCname\localSHAREname? I've had best luck using an actual UNC name to the server with the
full path specified. That is, if my website lives at \\remoteserver\remoteshare\folder1\folder2\application, I haven't had luck with \\remoteserver\remoteshare. I have to specify the whole path. Note also that I've had better luck using the full
UNC name and not a mapped drive letter (like X:\folder1\folder2\application). I can't really explain why this is, but it's been consistent on the few machines I've moved my sites between.
Hope this helps!
Nov 17, 2010 02:37 PM|StanMarsh|LINK
I tried the UNC name with full path for the ASP.NET website source folder. I also verified accessing the path was successful from another machine before my try.
The command line console returned "Added union code group with "-url" membership oncidition to the machine level. Success" after I executed the command above.
But I still have no luck. I restarted VS and still hit the
"System.Web.AspNetHostingPermission failed" error when using AJAX Control Toolkit. (Launch the web page can be successful without using AJAX)
I do the development on my local Win7 machine. I have the VS2010 and web server (IIS) on the same box.
I also tried below as suggested by another thread.
going to Start > Control Panel > Administrative Tools > Microsoft .NET Framework 2.0 Configuration. After it fully loads (sometimes takes a bit), fully expand My Computer in the navigation tree and click Runtime Security Policy. In the right hand pane, 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.
But the problem is that there is no "Microsoft.NET Framework 2.0 Configuration in Win7's Administrative Tools.
Anyone know how to do it via Command Line Console?
Nov 17, 2010 02:51 PM|alan.price|LINK
If that didn't work, the only other advice I have is to make sure that the path you're opening in Visual Studio matches the path you entered using CasPol. For instance, now that you've added
file:////\\server\share\folder1\folder2 using CasPol, re-open your project (website) in VS using the same full path. Also, make sure to use an elevated command prompt when running CasPol (if CasPol can
even run without full admin rights in the first place).
As to your question about the .NET 2.0 tool from Control Panel: that tool came with .NET Framework 2.0 when you installed it on XP or Server 2003 way back when. In Vista and Win7, .NET 2.0 is installed by default and is much more tightly integrated with
the system (i.e. it's not an add-on anymore). That tool disappeared, leaving, as far as I know, only CasPol for this type of security configuration. The newer .NET Frameworks are actually extensions of 2.0 and not completely new packages, like 2.0 was to
Hope this helps get you a little further.
Nov 17, 2010 06:09 PM|StanMarsh|LINK
Nope. It still didn't work.
I've done the following before my try.
1. Tried both VS 2010 Command Prompt and Command Prompt. Make sure it runs as a administrator
2. I can launch my VS solution successfully via that UNC path.
3. My VS project folder is shared.
Then, In the command line, I typed:
C:\Windows\Microsoft.NET\Framework\v2.0.50727>caspol.exe -m -ag 1 -url "file:////\\<servername>\Users\Administrator\Documents\Visual Studio 2010\Projects\<VSProjectName>\*" FullTrust
The "\\servername\sharefolder" UNC path is the same as the path I used to launch my VS solution
The command returned Success as below:
" The operation you are performing will alter security policy.
Are you sure you want to perform this operation? (yes/no)
Added union code group with "-url" membership condition to the Machine level.
I restarted VS 2010 after the command line execution. But it still hit "Request for the permission of type 'System.Web.AspNetHostingPermission" error.
I've also tried other commands like xcopy. xcopy can copy files from that UNC path to another folder without any problem.
Anything else I can do here?
Nov 18, 2010 09:26 PM|alan.price|LINK
You said earlier that you were using IIS to host the website locally. The path you mentioned implies that you have VS on one machine and your project/IIS on another? Is that correct? Or do you have VS, your project, and IIS all on your local machine (with
IIS pointing a virtual directory to the project folder)? If everything is local, you shouldn't need to use CasPol because the project directory should already be trusted. The exception comes from the of issue where
remote code is being compiled and it's untrusted by defult for security. If you're doing everything local, you shouldn't be seeing the System.Web.AspNetHostingPermission exception.
Let me know where your components (VS, project files, and IIS) reside and I might have an idea to help troubleshoot.
Nov 20, 2010 12:14 AM|StanMarsh|LINK
I have VS, my dev project, and IIS7 all installed on my local Win 7 machine. I use UNC path in the format of
\\<servername>\sharefolder as suggested on your post. The servername is my local machine name.
I hit "System.Web.AspNetHostingPermission" error on pages using AJAX control toolkit. The web pages without AJAX Control Toolkit can be access successfully.
I deleted the site pointing to the project folder and recreated it. I also tried restart IIS. But none of them work.
Let me know if there are anything I can help on your troubleshoot.
Nov 26, 2010 12:42 AM|alan.price|LINK
One quick thing to try that I've read about with IIS7: there might be some weird profile loading problem. Try this fix to see if it helps. I've never had to use it, but I haven't gotten to use IIS7.x for dev or production yet.
If that works, let me know. It may come in handy if my sites ever get moved to something newer than Server 2003...
If that doesn't work:
The location of your project should have been trusted when the project was created. It seems like something has gone wrong. What I'd try is to move/copy your project files (the .aspx, codefiles, Bin folder, etc.) to a subfolder under the inetpub root.
Then, do a File > Open Web Site and select that new folder. If it still won't build, add the path C:\inetpub\[newsubfolder]\* using CasPol. What's strange is I think VS trusts local locations by default. If everything is on one box, the site should just
build. If nothing works, it seems like there may be a problem in your VS install or with a security setting I've never had to use. Like I said, I've only run into the problem when I try to build a remote site. I've done done local builds on three or four
different machines with VS 2005 through 2010 and have never seen this happen (but I haven't had the chance to use an IIS7 server).
I hope one of these two does it!
Nov 30, 2010 08:15 PM|StanMarsh|LINK
I followed the instruction on the link
Set "Load User Profile" to true on the IIS7 ApplicationPool used by my website. The "Request for the permission of type System.Web.AspNetHostingPermission" error went away.
Dec 01, 2010 05:57 PM|alan.price|LINK
You're welcome! Glad to know this thread now contains two solutions to the problem.
Sep 09, 2015 07:26 PM|MatthewDaver|LINK
IT SOLVED MY ISSUE!!!
Thank you very much!!!!!
I was encountering unhanded permission exception whenever I mapped ( in IIS, server 2012) my web application to our Network Shared folder, (e.g. '\\computername\data\), but my web application worked if it was mapped to E: drive ( local drive not shared).
I was getting this error:
[SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +64
System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +58
System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +65
System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +342
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +52