简体   繁体   English

将网址和相对文件路径加入有效的网址?

[英]Joining Url and relative file path into valid Uri?

I have kind of a funky question- given the uri http://localhost , and a relative file path of virtualdirectory\\\\path\\\\to\\\\my\\\\file.html , how can I merge these into a valid Url which should be http://localhost/virtualdirectory/path/to/my/file.html ? 我有一个时髦的问题-给定uri http://localhost ,以及virtualdirectory\\\\path\\\\to\\\\my\\\\file.html的相对文件路径, virtualdirectory\\\\path\\\\to\\\\my\\\\file.html如何将它们合并到一个有效的Url中,是http://localhost/virtualdirectory/path/to/my/file.html吗?

I'm using Web.API and a client search to see if a static html file exists in a virtual directory on the server. 我正在使用Web.API和客户端搜索来查看服务器上的虚拟目录中是否存在静态html文件。 The client requests the search with jQuery, the Web.API controller does the searching on the local virtual directory. 客户端使用jQuery请求搜索,Web.API控制器在本地虚拟目录上执行搜索。 If the file does exist, the controller needs to return a valid Url to the client so the client can view that static html file. 如果该文件确实存在,则控制器需要向客户端返回有效的网址,以便客户端可以查看该静态html文件。

If that makes sense. 如果这样的话。 :) :)

new Uri(new Uri("http://localhost/"), "virtualdirectory\\path\\to\\my\\file.html".Replace("\\","/"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM