StructureMap, IIS 7.5 and FileIOException - iis

Howdy all. I am trying to solve a problem which is apparently not uncommon and I'm not sure how to find how this was resolved for folks. When I run StructureMap on my machine through IIS I get an exception and it looks like this:
**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.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
This question has come up here at SO (https://stackoverflow.com/questions/784666/), in the comments on this blog post and a year or so ago on the structuremap mailing list.
My problem is not running it in a foreign hosting environment. I can't even get it to run on my own box (IIS 7.5, Win7 RC, .NET 3.5). I have tried to configure the site to use a custom policy file and the FileIOPermission is marked to have unrestricted access...no dice. If anyone has some tips or a link it would be greatly appreciated.
Update
So there is no way that this is the best way to solve the problem, but after digging around and looking into what Joshua mentioned, these are the things I had to do to get it working: StructureMap, Code Access Security and a Bad Solution to a Problem. A better solution would be appreciated.

For what it's worth, I ran into this same issue where I had full control over the box and even set all the permissions to full trust. With IIS 7.5, I had to change the identity used for the specific application pool to NetworkService instead of ApplicationPoolIdentity. Once I restarted IIS, it worked.

FYI, I'm using StructureMap v2.6.1 and ran into this issue.
I do not use an XML configuration, so I added the following line to my configuration code, which fixed the problem.
IgnoreStructureMapConfig = true;

This is a bug, and has been fixed in the trunk. It will be included in the 2.6+ releases.
Some earlier versions of StructureMap would either attempt to unnecessarily write the dynamic assemblies to disk, or unnecessarily attempt to read from the filesystem.
If you are running in a restricted environment that does not allow access to full paths in the filesystem (ASP.NET), make sure to set IgnoreDefaultFile = true when you configure your container. Keep in mind this will disable the ability to load XML configuration from StructureMap.config.

Using the official StructureMap 2.5.4 build on Windows 7 with IIS 7.5 I still encountered this problem.
Mallioch's change
ObjectFactory.Initialize(x =>
{
x.UseDefaultStructureMapConfigFile = false;
x.IgnoreStructureMapConfig = true;
was necessary to resolve the FileIOPermission exception but I then received Request for the permission of type ‘System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed. which I resolved using Mike's solution ( for which I've created a step-by-step visualization ).

Related

What is this vague error with 'redirection.config' while building a Web Deploy package?

I'm trying to build a Web Deploy package via msbuild on a new machine and it's not working. It builds fine on other machines, but here I get the following vague error:
...\Microsoft.Web.Publishing.targets(2767,5): error : Filename: redirection.config
...\Microsoft.Web.Publishing.targets(2767,5): error : Error: Cannot read configuration file
...\Microsoft.Web.Publishing.targets(2767,5): error :
...\Microsoft.Web.Publishing.targets(2767,5): error : Unknown error (0x80005000)
I'm not sure what 'redirection.config' is, and the line reference to the .targets file doesn't help at all.
How can I fix this?
redirection.config is a file that lives in the IIS configuration directory, typically %SystemRoot%\System32\inetsrv\config. Here are two possibilities:
The account building your project doesn't have access to the IIS config dir. This might happen if you have an automated build identity with special permissions, or you if you need to start Visual Studio as an administrator.
You don't have IIS installed at all on the new machine. Check to be sure the IIS config directory, and redirection.config in particular, even exist. If not, you'll need to install IIS.
If you receive this error when deploying with Release Managment (via IISConfig.exe) be sure that the deployment agent service account is in the local Administrators group. You may need to restart the deployment agent service.
Similar Issue resolved below - Might help
Insufficient Permissions Problems with MSDeploy and TFS Build 2010
For me, simply running visual studio as admin gave it the elevated permissions it needed to operate against this folder.
May work for others.
I got this error when I tried to use a relative path for the contentPath setting. I fixed it by settings the contentPath to the full path of the folder. Without the full path, the contentPath provider thinks it is a site path or application path and looks for it in in the IIS configuration.
This error just appeared to me when my C# project was referencing the Microsoft.Web.Administration, Version=7.9.0.0 assembly. It looks like this assembly only works with IIS Express. For IIS, we must use Microsoft.Web.Administration, Version=7.0.0.0.
After hours of testing and troubleshooting this problem turned out to be an issue with the users profile.
This was found by logging in as myself and I didn't receive the same issue.
To fix this issue:
Log into the machine as an administrator and delete the contents of the corrupt profile from C:\Users (or rename the folder to username.OLD)
Open up the registry and navigate here – HKLM\SOFTWARE\Microsoft\Windows NT\ CurrentVersion\ProfileList
Find the corrupt profile and rename this to .OLD or remove it.
You can read more about it at this article.
As this is high in search engines when looking for this error, I'll post my solution.
I used Azure Pipelines to release the app to IIS and had this error. My issue was that I mistakenly used Build Agent job instead of Deployment Group job when configuring the release pipeline.
On server 2012 this error can be caused by UAC which needs to be disabled via the registry.
This article explains why...
https://social.technet.microsoft.com/wiki/contents/articles/13953.windows-server-2012-deactivating-uac.aspx
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system
change DWORD "EnableLUA" from 1 to 0

IIS not able to locate the web.config

I have a deployed a web application in IIS. Which used to work without any issues. Recently i have shifted that web application to another machine, Here is the problem. Once i setup the Webapplication when i opened the default document in IIS im getting the File not found error as following
Internal Server Error
\?\C:\inetpub\wwwroot\application\web.config
I have no clue why the IIS is not able to find the web.config. The file is present in the path C:\inetpub\wwwroot\application\web.config but the IIS is looking in the path \?\C:....
Please let me know how to resolve this??
Firstly this is documented on support.microsoft.com so I would suggest that anyone who has this issue read this first as it covers a number of solutions which I won't
Now from personal experience I encountered this error after setting up a new development machine. What I had forgotten to do was install the Url Rewrite 2.0 IIS module. Sadly the IIS error gives absolutely no idea that this is the actually issue.
Therefore to solve this issue investigate the system.webServer setting in our web.config and ensure that you have installed all the iis modules that you use. I did this by systematically removing elements from my web.config until I came across the cause.
In my case, I was running ASP .NET Core website so I had to install .Net Core Runtime from
https://dotnet.microsoft.com/download/dotnet-core/current/runtime
I know it's old post but I resolved the same issue as follows:
If you are using TFS and you are getting this problem then Reason is ".vs" file is not excluded from commit.
Because of that ".vs\config\applicationhost.config" gets the local version of another user/Developer.
To Solve the error, First open that file Update Physical path inside "" xml tag.
Also ask user to exclude this folder from TFS to prevent future issues.
If you are getting mysql localhost error. What I will do will work for you.
Control Panel(View by: Large Icons) >> Programs and Features >>
(Usually upper left corner) Turn Windows Features on or off >>
Internet Information Services >> Web Management Tools and World Wide Web Services
After Restart.

Private NuGet Gallery

I am trying to set up an internal nuget feed for my company. I have built the site and deployed it to IIS server. I can install from the site itf I manually add packages to it but I cannot push to it from the command line. When I try to I get prompted for credential (none work) then get an error that says "Cannot access a closed Stream." I have been to NuGet and read everything they propose but none of it works. I am thinking this is a server setting but I have no idea which one. Has anyone encountered this that can share the solution?
Solved this issue by removing WebDAV and adding PUT to the web.config authorization
I just added a comment to the Github issue tracker for a similar (probably identical) problem raised there:
https://github.com/NuGet/NuGetGallery/issues/487
This is probably a result of WebDAV being installed in IIS - it seems to interfere with the settings required for NuGet Gallery. We certainly saw a similar issue with 405 errors, and uninstalling the WebDAV module fixed the problem.

Setting up umbraco

hello i am trying to set up umbraco on my pc
i have followed each step
and when i try to lunch the site on iis i get this error
Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x80070032
Config Error The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration
Config File \?\C:\inetpub\wwwroot\cms\web.config
Requested URL http://localhost:80/cms
Physical Path C:\inetpub\wwwroot\cms
Logon Method Not yet determined
Logon User Not yet determined
any idea? please help
Try changing the version of .NET that the application pool is running under.
You've not mentioned which version of Umbraco you are using but I'm guessing 4.7.
If so you'll probably need to be running it under .NET4, unless you have specifically downloaded the .NET3.5 version direct from Codeplex.
try to change the port to other number rather than using default 80 port.
hope this helps

Deploy Web Part Into windows server 2008 R2

I have build one employee directory webpart that gets necessary information of user from sharepoint site. i have deployed in my testing server "Windows Server 2003 and Moss2007" and it's work fine.
When i tried to deploy on my production server "Windows Server 2008 R2 with Moss2007". It give me security error.
Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed."
I have also created security policy file and added reference to web.config. Still i getting same error please help on this. i am stuck here and not able to find any way to get out of this.
Thanks in advance.
Do you install your DLL into GAC? You must either install it into GAC (the solution does it for you if you specify the assembly location as GAC) or provide a custom CAS policy and register that policy in the web.config file. We usually prefer the first way, unless a customer specifically requires a custom CAS policy. This is much easier and I really doubt the security-wise effectiveness of the custom policy approach (unless your IT department actually goes over your code and examines what it can and cannot do, haven't found a department that would know how to do that)

Resources