[英]Path equivalent in asp.net (C#)?
Whats the equivalent to System.IO.Path ? 等效于System.IO.Path是什么?
I got this url: http://www.website.com/category1/category2/file.aspx?data=123 我得到了这个网址: http : //www.website.com/category1/category2/file.aspx? data= 123
How can i break this down, like 我该如何分解,例如
var url = ASPNETPATH("http://www.website.com/category1/category2/file.aspx?data=123");
url.domain <-- this would then return http://www.website.com
url.folder <-- would return category1/category2
url.file <-- would return file.aspx
url.queryString <-- would return the querystring in some format
Use the UriBuilder
class: 使用
UriBuilder
类:
http://msdn.microsoft.com/en-us/library/system.uribuilder.aspx http://msdn.microsoft.com/zh-CN/library/system.uribuilder.aspx
UriBuilder uriBuilder = new UriBuilder("http://www.somesite.com/requests/somepage.aspx?i=123");
string host = uriBuilder.Host; // www.somesite.com
string query = uriBuilder.Query; // ?i=123
string path = uriBuilder.Path; // /requests/somepage.aspx
查看URI类,您可以使用该类获取所有信息。
Regular expressions are perfect to use for this. 正则表达式非常适合用于此目的。 Here's a link that has some nice info on using them.
这是一个有关使用它们的不错信息的链接。 http://www.regular-expressions.info/
http://www.regular-expressions.info/
Edit : I forgot C# has a URI class which you can use for this as well. 编辑:我忘记了C#有一个URI类,您也可以使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.