更新时间:2023-02-23 16:54:13
VAR基本URI =新的URI(http://my.server.com/folder/directory/sample);
变种绝对URI =新的URI(基本URI,../../等/路径);
或
开放的URI;
如果(Uri.TryCreate(HTTP://基/,../relative,出URI))的doSomething(URI);
I have a base URL :
http://my.server.com/folder/directory/sample
And a relative one :
../../other/path
How to get the absolute URL from this ? It's pretty straighforward using string manipulation, but I would like to do this in a secure way, using the Uri
class or something similar.
It's for a standard a C# app, not an ASP.NET one.
var baseUri = new Uri("http://my.server.com/folder/directory/sample");
var absoluteUri = new Uri(baseUri,"../../other/path");
OR
Uri uri;
if ( Uri.TryCreate("http://base/","../relative", out uri) ) doSomething(uri);