Reputation: 26993
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
.
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"?
Upvotes: 1
Views: 1277
Reputation: 26993
Server.MapPath returns the string "NOT_A_VALID_FILESYSTEM_PATH" when both of the following are true:
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."
Upvotes: 8