简体   繁体   English

ASP.NET拒绝访问临时目录

[英]ASP.NET Access to the temp directory is denied

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页面访问Web服务时会发生这种情况

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)

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 -i command to re-install the asp.net framework which also resets the permissions on the required folders. 在这些情况下,最简单,最快速的解决方案通常是重新运行aspnet_regiis -i命令来重新安装asp.net框架,该框架也会重置所需文件夹的权限。 Failing that, try using Process Monitor to check what's going on and modify the permissions accordingly. 如果做不到这一点,请尝试使用Process Monitor检查发生了什么并相应地修改权限。

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 link about 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 Monitor to verify this was in fact correct, when we changed the permission on this folder it worked correctly. 然后我们使用Process Monitor来验证这实际上是正确的,当我们更改了它正确工作的文件夹的权限时。 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. 我们仍然不确定为什么CLR选择停止使用默认的临时目录,但我们确实找到了一个关于它如何做出决定的链接。 How GetTempPath is picked . 如何选择GetTempPath

Update: We Finally figured out HOW our Temp folder PATH was changed when Someone decided to repeat the error! 更新:我们终于弄清楚当有人决定重复错误时,我们的Temp文件夹PATH如何更改! The Issue was the CLR Profiler someone decided 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 有人决定在live上运行,它改变了temp目录的所有权限,所以如果你还不知道这个,我不建议在Prod服务器上运行它。

Windows Server 2003 - IIS 6.0 - Same issue. Windows Server 2003 - IIS 6.0 - 同样的问题。 c:\\windows\\temp = current temp directory - using procmon as suggested by cgreeno allowed me to see access denied. c:\\ windows \\ temp =当前临时目录 - 使用cgreeno建议的procmon允许我看到访问被拒绝。 I granted the user 'Everyone' full rights to the c:\\windows\\temp folder, but still getting access denied. 我授予用户'Everyone'对c:\\ windows \\ temp文件夹的完全权限,但仍然拒绝访问。 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. 试过ASPNET_REGIIS -ir但没有帮助。

I created a new local system user 'tempuser' and assigned to local 'Administrators' group. 我创建了一个新的本地系统用户'tempuser'并分配给本地'Administrators'组。 I navigated to Windows Services and stopped 'World Wide Web Publishing', 'IIS Admin', and 'HTTP SSL'. 我导航到Windows服务并停止了“万维网发布”,“IIS管理”和“HTTP SSL”。 I assigned 'tempuser' to all three services. 我为所有三项服务分配了'tempuser'。 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. 然后我将所有3个服务都放回用户的“本地系统”,突然我的访问被拒绝错误就消失了。 Don't know why. 不知道为什么。 Was having other file system errors with my App Pool user, but those now are working correctly too. 我的App Pool用户遇到了其他文件系统错误,但现在这些错误也正常。 It appears something with the assignment of the Local System account with windows services was awry. 看起来与Windows服务的本地系统帐户的分配是错误的。

* UPDATE * *更新*

Problem came back. 问题回来了。 Very weird... 很奇怪...

在我的情况下,防病毒软件(COMDO)对此负责...在防病毒更新后,它刚刚开始阻止访问我的本地服务的临时文件夹(不是全部,只有少数)......想出来有点棘手......

转到roslyn文件夹(进入项目的bin foloder)并在运行应用程序池的用户处添加读/写权限

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. 转到该目录并为用户“NETWORK SERVICE”提供所需的权限,可能是“读/写”。

Indeed its a web site running in IIS? 确实是一个在IIS中运行的网站? and accessing a web service. 并访问Web服务。

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可以更改安全设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM