c# - Cascade a url string -


coming this question, i'm looking way cascade url path.combine file system including path-parameter.

my input following 3 parameters:

string host = "test.com"; //also possilbe: "test.com/" string path = "/foo/"; //also possilbe: "foo", "/", "","/foo","foo/" string file = "test.temp"; //also possilbe: "/test.temp" 

the expected result is

http://test.com/foo/test.temp

this approach best find does'n work cases:

uri myuri = new uri(new uri("http://" + host +"/"+ path), file); 

you try using uri.trycreate():

uri uri; bool success = uri.trycreate(new uri("http://" + host), path.trim('/') + "/" + file.trim('/'), out uri); 

this return false if url somehow in incorrect format. however, if sure format correct, can use uri constructor:

var uri = new uri(new uri("http://" + host), path.trim('/') + "/" + file.trim('/')); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -