[英]ASP.NET: Server.MapPath returns the string NOT_A_VALID_FILESYSTEM_PATH
In my ASP.NET application, a method that is supposed to write a file to disk sometimes unexpectedly ends up writing the file with the filename NOT_A_VALID_FILESYSTEM_PATH
. 在我的ASP.NET应用程序中,应该将文件写入磁盘的方法有时会意外地以文件名
NOT_A_VALID_FILESYSTEM_PATH
写入文件。
The (simplified) code is: (简化的)代码是:
private void WriteFile(string fileID)
{
string fileName = Server.MapPath("/Data/" + fileID + ".xml");
// (More code that writes data to that file...)
}
Why is Server.MapPath returning the string "NOT_A_VALID_FILESYSTEM_PATH"? 为什么Server.MapPath返回字符串“ NOT_A_VALID_FILESYSTEM_PATH”?
Server.MapPath returns the string "NOT_A_VALID_FILESYSTEM_PATH" when both of the following are true: 满足以下两个条件时, Server.MapPath返回字符串“ NOT_A_VALID_FILESYSTEM_PATH”:
If the web.config doesn't have the relaxedUrlToFileSystemMapping="true"
, then the call to Server.MapPath will instead throw a System.NotSupportedException with the message "The given path's format is not supported." 如果web.config不具有
relaxedUrlToFileSystemMapping="true"
,则对Server.MapPath的调用将引发System.NotSupportedException并显示消息“不支持给定路径的格式”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.