简体   繁体   中英

Path equivalent in asp.net (C#)?

Whats the equivalent to System.IO.Path ?

I got this url: 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:
http://msdn.microsoft.com/en-us/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/

Edit : I forgot C# has a URI class which you can use for this as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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