Path.Combine for URLs?(用于 URL 的 Path.Combine?)
问题描述
路径.合并 很方便,但在 .NET 框架中是否有类似的功能用于 URLs?
Path.Combine is handy, but is there a similar function in the .NET framework for URLs?
我正在寻找这样的语法:
I'm looking for syntax like this:
Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")
会返回:
http://MyUrl.com/Images/Image.jpg"
推荐答案
有是一个上面 Todd Menier 的评论 说 Flurl 包含一个 Url.Combine代码>.
There is a Todd Menier's comment above that Flurl includes a Url.Combine.
更多细节:
Url.Combine 基本上是 URL 的 Path.Combine,确保一个部分之间只有一个分隔符:
Url.Combine is basically a Path.Combine for URLs, ensuring one and only one separator character between parts:
var url = Url.Combine(
"http://MyUrl.com/",
"/too/", "/many/", "/slashes/",
"too", "few?",
"x=1", "y=2"
// result: "http://www.MyUrl.com/too/many/slashes/too/few?x=1&y=2"
在 NuGet 上获取 Flurl.Http:
Get Flurl.Http on NuGet:
PM> 安装包 Flurl.Http
PM> Install-Package Flurl.Http
或者获取独立的 URL 构建器,没有 HTTP 功能:
Or get the stand-alone URL builder without the HTTP features:
PM> 安装包Flurl
PM> Install-Package Flurl
这篇关于用于 URL 的 Path.Combine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于 URL 的 Path.Combine?
基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
