开发者

Setting HttpContext.Current.Request.Url.Host

I need to replace the host part of the Uri

HttpContext.C开发者_如何转开发urrent.Request.Url.Host = "newDomain";

you can't set host. Is there a quick and easy way to do this to a Uri for reusing it to redirect somewhere else?


Use the UriBuilder class to change URIs, e.g.

var original = HttpContext.Current.Request.Url;
var changed = (new UriBuilder(original) { Host = "newDomain" }).Uri;

URIs are tricky little beasts with plenty of semantics you might not know or expect, so don't go using string functions on them unless you absolutely have to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜