【问题标题】:How to set the Temp path ie. the value returned by Path.GetTempPath()?如何设置临时路径,即。 Path.GetTempPath() 返回的值?
【发布时间】:2009-07-31 11:17:02
【问题描述】:

我试图在模拟下运行一个 ASP.net 2.0 站点,但似乎出了点问题。我在 ASP.Net IIS 配置小程序中撤消了我的更改。

但是现在我被这个错误困住了

System.UnauthorizedAccessException: Access to the temp directory is denied.  Identity 'MACHINE\ASPNET' 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)

所以我尝试更改临时路径 - 但是 MSDN 没有说明它是如何得出这个值的。我尝试设置 TEMP 和 TMP 环境变量,但这也没有影响它。它仍然指向 C:\Tmp 文件夹,由于某些管理策略,该文件夹被映射为驱动器,显然来自这些部分周围的类似 Mordac 的字符。

更新:似乎该更改现在才生效。 Path.GetTempPath 现在显示我为这 2 个环境变量设置的值。

【问题讨论】:

    标签: c# path asp.net-2.0


    【解决方案1】:

    您可以显式更改 XMLSerializer 的临时路径,而无需更改机器的环境变量。为此,请将

    <xmlSerializer tempFilesLocation="c:\\newTemp"/> 
    

    在您的 app.config 文件中。

    Scott Hanselman 有一篇题为“Changing where XmlSerializer Outputs Temporary Assemblies”的文章。

    【讨论】:

      【解决方案2】:

      使用\\live.sysinternals.com\tools\ProcMon.exe 来确定写作的地点,但我想你已经知道在哪里了。

      然后您可以为被拒绝的身份分配所需的权限。

      在这种情况下,Machine\ASPNET 需要在您的临时目录所在的任何位置创建和写入。

      如果您使用环境变量,ASP.NET 进程将需要重新启动才能获取修改,但您仍然会遇到问题,因为默认情况下会为目录应用一组保护这可以防止多个 indeitities 形成写入同一区域。

      【讨论】:

      • 我尝试使用 2 个管理员用户帐户运行,但它仍然给出相同的错误,并在错误消息中提及管理员用户名。所以我不确定这里发生了什么......
      • 您是否修改了临时目录上的文件安全性以允许 ASPNET 用户在其中写入文件?除非您确定基于 procmon 的东西或让应用程序池以该管理员用户身份运行(即不依赖于模拟),否则可能就是问题所在。不幸的是,我现在需要离线很长时间,所以我希望你能坚持一下,或者其他人会这样做!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多