【问题标题】:Path combine question [duplicate]路径组合问题[重复]
【发布时间】:2011-05-10 01:19:19
【问题描述】:

可能重复:
Path.Combine for Urls?

我有一个像http://localhost/ 这样的根目录

我有一个名为 sample.jpg 的文件名

当我使用 Path.Combine(root, file) 时,我得到类似http://localhost\sample.jpg 的东西,我想知道我是否可以得到http://localhost/sample.jpg

【问题讨论】:

  • 确实,当您组合 url 部分时,例如编码、转义、查询字符串、被截断的虚拟路径,会有很多含义。如果您需要更全面的解决方案,可以查看此答案:stackoverflow.com/a/23399048/3481183

标签: c# .net


【解决方案1】:

Path.Combine 是为文件系统路径设计的,而不是 URL,所以我认为在这种情况下它不会给你想要的东西。您可以随时输入Path.Combine,然后输入String.Replace("\", "/") 来更正您的网址。

【讨论】:

    猜你喜欢
    • 2019-06-01
    • 2017-12-09
    • 2011-08-29
    • 2022-11-22
    • 2017-12-30
    • 1970-01-01
    • 2021-08-03
    • 2010-12-17
    • 1970-01-01
    相关资源
    最近更新 更多