Server.MapPath and spaces

I noticed something strange in Server.MapPath (). If I have a folder with a space at the end, I get:

HttpException: Failed to map path.

This works great: Server.MapPath("/Folder1/Folder2/item.jpg")

This works great: Server.MapPath("/Folder1/ Folder2/item.jpg")

This works great: Server.MapPath("/Folder1/Fol der2/item.jpg")

This fails :: Server.MapPath("/Folder1/Folder2 /item.jpg")

Can someone explain to me why the space at the end fails, but not elsewhere?

Note. None of the folders exist.

+5
source share
3 answers

Because you should not :

Do not end the file or directory name with a space or period. Although the underlying file system may support such names, the shell and the Windows user interface do not. However, it is permissible to specify the period as the first character of the name. For example, ".temp".

FileUtil.IsSuspiciousPhysicalPath(string physicalPath, out bool pathTooLong), :

string.Compare(physicalPath, Path.GetFullPath(physicalPath), StringComparison.OrdinalIgnoreCase) != 0;

Path.GetFullPath() ( Path.NormalizePath(), ), , , Path.GetFullPath(@"C:\Foo \Bar.txt"). , , true, , Server.MapPath .

+2

MapPath . , . Directory.Exists() File.Exists(), , .

if (File.Exists(Server.MapPath(file)) 

, :

(*)
(?)
(< > )
Comma (,)
(: ;)
( "" )
(])
(// \)

, .

+2

Visual Studio 2010 Microsoft.NET

post, , .net, server.MapPath .net. , , ,

- System\Web\httpserverutility.cs\1477467\httpserverutility.cs -MapPath

- \ System\Web\VirtualPath.cs\1477467\VirtualPath.cs * * -

-System\Web\HttpRequest.cs\1599819\HttpRequest.cs -MapPath

, strage null, path is/folder1/folder2/file.cs, reutn null object /folder 1/folder2/file.cs

, , happnen

, .. Microsoft, framewok


, i.e "Folder2". .

- Windows, sapce namei.e .

+1

All Articles