C# ASP.NET 访问临时目录被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/542312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET Access to the temp directory is denied
提问by Luca Martinetti
I'm experiencing this problem today on many different servers.
我今天在许多不同的服务器上都遇到了这个问题。
System.UnauthorizedAccessException: Access to the temp directory is denied.
System.UnauthorizedAccessException:拒绝访问临时目录。
The servers were not touched recently. The only thing that comes in my mind is a windows update breaking something.. Any idea?
最近没有接触服务器。我唯一想到的是 Windows 更新破坏了某些东西.. 知道吗?
This happens when trying to access a webservice from an asp.net page
尝试从 asp.net 页面访问网络服务时会发生这种情况
System.UnauthorizedAccessException: Access to the temp directory is denied. Identity 'NT AUTHORITY\NETWORK SERVICE' under which XmlSerializer is running does not have sufficient permission to access the temp directory. CodeDom will use the user account the process is using to do the compilation, so if the user doesnt have access to system temp directory, you will not be able to compile. Use Path.GetTempPath() API to find out the temp directory location.
at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Evidence evidence)
at System.Web.Services.Protocols.XmlReturn.GetInitializers(LogicalMethodInfo[] methodInfos)
at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
采纳答案by Mun
Have you checked the permissions on the temp folder? In these cases, the easiest and quickest solution is usually to re-run the aspnet_regiis -icommand to re-install the asp.net framework which also resets the permissions on the required folders. Failing that, try using Process Monitorto check what's going on and modify the permissions accordingly.
您是否检查过临时文件夹的权限?在这些情况下,最简单快捷的解决方案通常是重新运行aspnet_regiis -i命令以重新安装 asp.net 框架,该框架还会重置所需文件夹的权限。如果失败,请尝试使用Process Monitor检查发生了什么并相应地修改权限。
回答by Jim Counts
Whatever the reason for the sudden change, you can probably solve the problem using the steps described in the exception.
无论突然变化的原因是什么,您都可以使用异常中描述的步骤解决问题。
Call Path.GetTempPath to find out what it thinks the temporary directory is, it may not be what you think it is.
调用 Path.GetTempPath 找出它认为临时目录是什么,它可能不是你认为的那样。
Go to that directory and give the user 'NETWORK SERVICE' the permissions it needs, probably Read/Write.
转到该目录并授予用户“网络服务”所需的权限,可能是读/写。
回答by Robert
Indeed its a web site running in IIS? and accessing a web service.
它确实是一个在 IIS 中运行的网站?并访问网络服务。
It's either running as ASPNET, anonymous, or impersonating the user connected or finally the web service itself is connecting as a 'user'.
它要么作为 ASPNET 运行,要么匿名运行,要么模拟连接的用户,或者最终 Web 服务本身作为“用户”连接。
Whichever user it is may not have access to the temp directory. Odd how nothing has changed :). However Windows Service packs can change security settings.
无论是哪个用户,都可能无权访问临时目录。奇怪的是什么都没有改变:)。但是,Windows Service Pack 可以更改安全设置。
回答by cgreeno
I had the same issue and none of the above solved our issue -- we restored service temporally by changing the setting that each app pool site was running under - you can do this by going into app pools--> idenity tab and and changing user from Network Service to local user- while we figured out what the problem was(this is not recommended- so if you choose to do this make sure you understand the repercussions)
我遇到了同样的问题,以上都没有解决我们的问题——我们通过更改每个应用程序池站点在其下运行的设置来临时恢复服务——您可以通过进入应用程序池--> 身份选项卡并更改用户来完成此操作从网络服务到本地用户-虽然我们找出了问题所在(不推荐这样做-因此,如果您选择这样做,请确保您了解后果)
We then found a linkabout the Temp\TMP mappings and how to fix them -Which was not our issue
然后,我们发现了一个链接有关TEMP \ TMP映射,以及如何解决这些问题哪位不是我们的问题
On another site(and as described in other answers) we used Path.GetTempPath()
to see what the CLR was actually looking for it turned out to be
在另一个站点上(如其他答案中所述),我们过去常常Path.GetTempPath()
看到 CLR 实际在寻找它的结果是
C:\WINDOWS\system32\config\systemprofile\Local Settings\Temp folder
C:\WINDOWS\system32\config\systemprofile\Local Settings\Temp 文件夹
We then used Process Monitorto verify this was in fact correct, when we changed the permission on this folder it worked correctly. We are still unsure as to why the CLR choose to stop using the default temp directory but we did find a link as to how it makes that decision. How GetTempPath is picked.
然后我们使用Process Monitor来验证这实际上是正确的,当我们更改此文件夹的权限时,它可以正常工作。我们仍然不确定为什么 CLR 选择停止使用默认的临时目录,但我们确实找到了一个关于它如何做出决定的链接。如何选择 GetTempPath。
Update: We Finally figured out HOW our Temp folder PATH was changed when Someone decided to repeat the error! The Issue was the CLR Profilersomeonedecided to run on live which changes all permissions of the temp directory so If you didn't already know this already I would not recommend running it on a Prod server.
更新:我们终于弄清楚了当有人决定重复错误时我们的临时文件夹路径是如何改变的!问题是有人决定在实时运行的CLR Profiler更改临时目录的所有权限,因此如果您还不知道这一点,我不建议在 Prod 服务器上运行它。
回答by barrypicker
Windows Server 2003 - IIS 6.0 - Same issue. c:\windows\temp = current temp directory - using procmon as suggested by cgreeno allowed me to see access denied. I granted the user 'Everyone' full rights to the c:\windows\temp folder, but still getting access denied. Granted full rights access to all users in the mix (Local System, Network Service, app pool identity user, etc.) but no help. Tried ASPNET_REGIIS -ir but no help.
Windows Server 2003 - IIS 6.0 - 同样的问题。c:\windows\temp = 当前临时目录 - 按照 cgreeno 的建议使用 procmon 允许我看到访问被拒绝。我授予用户“所有人”对 c:\windows\temp 文件夹的完全权限,但仍然拒绝访问。向混合中的所有用户(本地系统、网络服务、应用程序池身份用户等)授予完全权限访问权限,但没有帮助。试过 ASPNET_REGIIS -ir 但没有帮助。
I created a new local system user 'tempuser' and assigned to local 'Administrators' group. I navigated to Windows Services and stopped 'World Wide Web Publishing', 'IIS Admin', and 'HTTP SSL'. I assigned 'tempuser' to all three services. I tried to start each of the services, but they failed to start for a variety of reasons. I then put all 3 services back to user 'Local System' and suddenly my access denied error went away. Don't know why. Was having other file system errors with my App Pool user, but those now are working correctly too. It appears something with the assignment of the Local System account with windows services was awry.
我创建了一个新的本地系统用户“tempuser”并分配给本地“管理员”组。我导航到 Windows 服务并停止了“万维网发布”、“IIS 管理”和“HTTP SSL”。我为所有三个服务分配了“tempuser”。我尝试启动每项服务,但由于各种原因未能启动。然后我将所有 3 个服务都放回用户“本地系统”,突然我的访问被拒绝错误消失了。不知道为什么。我的 App Pool 用户有其他文件系统错误,但现在也可以正常工作。似乎与 Windows 服务的本地系统帐户的分配有问题。
* UPDATE *
* 更新 *
Problem came back. Very weird...
问题又来了。很奇怪...
回答by Janis Rudovskis
In my case antivirus(COMDO) was responsible for this... After antivirus updated it just started to block access to temp folder for my local services(not all, just few) ... it was kinda tricky to figure it out..
在我的情况下,防病毒软件(COMDO)对此负责......在防病毒软件更新后,它开始阻止访问我的本地服务的临时文件夹(不是全部,只是少数)......弄清楚它有点棘手..
回答by Diego
Goto into roslyn folder (into bin foloder of your project) and add the read/write permissions at the user which runs the application pool
进入 roslyn 文件夹(进入项目的 bin 文件夹)并在运行应用程序池的用户处添加读/写权限