gpt4 book ai didi

c# - Server.MapPath 问题?

转载 作者:行者123 更新时间:2023-11-30 16:21:26 24 4
gpt4 key购买 nike

所以我正在读一本关于 asp.net 安全的书。其中一个部分是:如何防止目录遍历文件名(被黑的文件名)。

所以这行代码是:

string fullPath = Server.MapPath(System.IO.Path.Combine(@"d:\inetpub\inbound\",filename));

但后来我注意到联合收割机的结果将是:

d:\inetpub\inbound\myfile.txt

但是我记得参数类型应该是虚拟路径而不是文件系统路径!

enter image description here

d:\inetpub\inbound\myfile.txt 不是虚拟路径!

我错过了什么?

enter image description here

附注这是书 : (wrox)

enter image description here

最佳答案

代码示例错误。

Server.MapPath的作用确实是将虚拟路径转换为物理路径。如果您已有物理路径,则不需要 Server.MapPath

代码可能会抛出异常并显示消息:

'd:\inetpub\inbound\myfile.txt' is a physical path, but a virtual path was expected.

关于c# - Server.MapPath 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13247123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com