【问题标题】:tempDirectory compilation configurationtempDirectory 编译配置
【发布时间】:2010-04-27 15:36:14
【问题描述】:

我想将<compilation tempDirectory="MyPath"/> 添加到我的网络服务的 web.config 中。

是否可以指定相对路径?还是只能走绝对路径?

【问题讨论】:

  • 你解决了相对路径问题吗?无法设置相对路径似乎很荒谬。当站点不在您的场所并且 ISP 没有告诉您托管站点的绝对路径时应该怎么做?

标签: c# .net web-services


【解决方案1】:

转到 webconfig 文件,仅删除路径。

这通常是文件从一个域移动到另一个域时引起的。

【讨论】:

    【解决方案2】:

    来自tempDirectory,

    指定编译期间用于临时文件存储的目录。

    我认为你最好的选择是绝对路径;但是,你可以试试这样的亲戚:

    <compilation tempDirectory="Default Web Site/YourApp"/>
    

    【讨论】:

    • 我想让 tempDirectory 与 web 服务处于相同的位置...我尝试了 tempDirectory = "Temp" ...它抱怨它需要是绝对路径。 :(
    【解决方案3】:

    temp目录处理如下:

       if ((compilationSection != null) && !string.IsNullOrEmpty(compilationSection.TempDirectory))
    {
        path = compilationSection.TempDirectory;
        compilationSection.GetTempDirectoryErrorInfo(out tempDirAttribName, out configFileName, out configLineNumber);
    }
    if (path != null)
    {
        path = path.Trim();
        if (!Path.IsPathRooted(path))
        {
            path = null;
        }
        else
        {
            try
            {
                path = new DirectoryInfo(path).FullName;
            }
            catch
            {
                path = null;
            }
        }
        if (path == null)
        {
            throw new ConfigurationErrorsException(SR.GetString("Invalid_temp_directory", new object[] { tempDirAttribName }), configFileName, configLineNumber);
        }
    

    如果 (path[0] is '\' or '/') or (path[1] is ':') 则 IsPathRooted 返回 true

    设置相对路径:

    <compilation tempDirectory="/Default Web Site/YourApp"/>
    

    【讨论】:

    • 就我从测试 (VS2017) 和阅读代码中看到的那样,这样的路径将被解释为根路径,这意味着 /Default Web Site/YourApp 文件夹最终会位于驱动器的根目录中.似乎没有任何方法可以指定相对文件夹。
    【解决方案4】:

    没有办法指定相对路径,错误信息也清楚地表明了这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-30
      • 2016-10-06
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      相关资源
      最近更新 更多