我在寻找改变一个给定的的System.Uri 实例与 System.UriBuilder 没有蹩脚的字符串操作和魔术常量。说我有
I'm looking for canonical way of changing scheme of a given System.Uri instance with System.UriBuilder without crappy string manipulations and magic constants. Say I have
var uri = new Uri("http://localhost/hello")
和我需要将其更改为 HTTPS 。我的问题是有限的 UriBuilder
构建函数和 Uri.Port
默认为80(我们应该将其更改为443?硬编码? )。在code必须尊重所有乌里
属性,如可能的基本身份验证凭据,查询字符串,等等。
and I need to change it to 'https'. My issue is in limited UriBuilder
ctors and Uri.Port
defaulting to 80 (should we change it to 443? hardcoding?). The code must respect all Uri
properties such as possible basic auth credentials, query string, etc.
结束了这一个:
var uriBuilder = new UriBuilder(requestUrl)
{
Scheme = Uri.UriSchemeHttps,
Port = -1 // default port for scheme
};
上一篇:确定对象从集合类型派生对象、类型
下一篇:ASP.NET网页的冲突版本检测:指定的版本是" 1.0.0.0"但是在bin中的版本是" 2.0.0.0"在ASP.MET MVC 3版本、冲突、网页、但是在