【发布时间】:2010-04-27 15:36:14
【问题描述】:
我想将<compilation tempDirectory="MyPath"/> 添加到我的网络服务的 web.config 中。
是否可以指定相对路径?还是只能走绝对路径?
【问题讨论】:
-
你解决了相对路径问题吗?无法设置相对路径似乎很荒谬。当站点不在您的场所并且 ISP 没有告诉您托管站点的绝对路径时应该怎么做?
标签: c# .net web-services
我想将<compilation tempDirectory="MyPath"/> 添加到我的网络服务的 web.config 中。
是否可以指定相对路径?还是只能走绝对路径?
【问题讨论】:
标签: c# .net web-services
转到 webconfig 文件,仅删除路径。
这通常是文件从一个域移动到另一个域时引起的。
【讨论】:
指定编译期间用于临时文件存储的目录。
我认为你最好的选择是绝对路径;但是,你可以试试这样的亲戚:
<compilation tempDirectory="Default Web Site/YourApp"/>
【讨论】:
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"/>
【讨论】:
/Default Web Site/YourApp 文件夹最终会位于驱动器的根目录中.似乎没有任何方法可以指定相对文件夹。
没有办法指定相对路径,错误信息也清楚地表明了这一点。
【讨论】: