“CS0016: Could not write to output file” error whe

2020-02-08 07:54发布

I am running Windows 7, and am not usually a developer in this setting, and have recently built a WCF Rest Service in C#, that I'm now trying to deploy to IIS just on my local machine. After much wrangling, I setup up the application, but when I navigate to the application, I get an error message: Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\scom_sibyll\8c0b945e\9329016\App_global.asax.eagmqgcd.dll' -- 'Access is denied. '

I have hunted the web to the best of my ability, and have changed the permissions on the Temporary ASP.NET Files fodler to allow the Network Service account full rights, and done the same with the Temp folder. It copies a number of files before failing, so it has write permissions presumably, so I checked the permissions to read from my source folder, and that is working as well. I additionally noted it's crapping out when it tries to to cache the DLL file, and tried turning off my Antivirus protection, as well as turning off UAC, just to see if I could figure out what is blocking this from occurring. I'm fresh out of ideas now. Anybody have any suggestions?

13条回答
Explosion°爆炸
2楼-- · 2020-02-08 08:26

Some times the Temp files might be locked by other process in the workstation. As a first step please reboot the workstation and check the application.

查看更多
萌系小妹纸
3楼-- · 2020-02-08 08:28

On Windows 8/Server 2012 there is no support for aspnet_regiis any more. I tried reinstall using windows features: fail. I tried reinstalling IIS: fail. I tried reinstall through WebPI: fail.

I solved the issue by setting the ACL's on the Windows Temp Directory.

Here is a powershell that does the job:

$dir = "C:\Windows\Temp"
$acl = get-acl -path $dir
$new = "IIS_IUSRS","Modify","ContainerInherit,ObjectInherit","None","Allow"
$accessRule = new-object System.Security.AccessControl.FileSystemAccessRule $new
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $dir
查看更多
何必那么认真
4楼-- · 2020-02-08 08:29

For those looking here as I did, if the accepted answer doesn't resolve the issue you might try following this article: http://lordzoltan.blogspot.com/2011/02/aspnet-2-and-4-default-application-pool.html

In summary, it seems that the same error is sometimes displayed when the app pool user doesn't have access to the %TMP%/%TEMP% folder.

You'll need to grant IIS_IUSRS read and modify access over the temp folder of the user the app pool is running as.

This could either be the temp folder in the app pool user's profile, e.g. c:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp, or the system temp folder at c:\windows\temp.

Setting this up this resolved the issue for me.

查看更多
Deceive 欺骗
5楼-- · 2020-02-08 08:31

I started getting this error too recently in a corporate environment after the company implemented various security measures that took away admin rights from the users.

For developers, the company authorized the creation of accounts that could be used and we had to add these to the PC's admin group and then change the application pool's identity to use the account.

EXAMPLE (Windows 10)

Account created for developers: domain\developer

Someone with admin rights to the PC will have to do the following:

  • Go to Control Panel\User Accounts\Manage User Accounts
  • Click on the Advanced tab, and click on the Advanced user management button
  • In the lusrmgr page, click on the Groups folder in the left column to bring up groups in the center panel
  • Then secondary-click on the Administrators group and select "Add to Group..."
  • In the Administrators Properties panel, click the "Add..." button
  • A "Select Users, Computers, Service Accounts, or Groups" dialog opens. Add the account (domain\developer in this example)
  • Then click on the OK button (this button will be disabled if you don't have admin rights)

Now configure the App Pool:

  • Open IIS Manager, select Application Pools
  • Click on the application pool you want so it's highlighted, then click "Advanced Settings..." from the Actions panel on the right
  • Under the Process Model section, click on the Identity setting and the ellipses button
  • In the Application Pool Identity dialog, select "Custom account" and then click the Set button
  • Enter the account and the password

At this point I was able to close everything, restart IIS and then run my app. It could then access the temp folders it couldn't before.

查看更多
淡お忘
6楼-- · 2020-02-08 08:34

I have permissions but I'm starting to get that error. "restart machine" works for me

查看更多
对你真心纯属浪费
7楼-- · 2020-02-08 08:35

I granted read and write access to C:\Windows\Temp for the IIS_WPG group. This worked for me. I'm on Server 2003 R2 and IIS 6 and the group name is different. I fount it from http://learn.iis.net/page.aspx/140/understanding-built-in-user-and-group-accounts-in-iis/ where it says:

•The IUSR built-in account replaces the IUSR_MachineName account.

•The IIS_IUSRS built-in group replaces the IIS_WPG group.

Thanks to Dommer for suggesting the windows temp folder and to zcrar70 for the nice summery and a link with detailed description.

查看更多
登录 后发表回答