简体   繁体   中英

how to manipulate the URL path in c# asp.net?

I have the following path:

-http://localhost/portal/reportview.aspx

but I need to retrieve the first 3 parts:

-http://localhost/portal/

Ive tried HttpContext.Current.Request.Url.GetLeftPart(); with no luck.

You can use substring.

string str = "http://localhost/portal/reportview.aspx";

string left = str.Substring(0, str.LastIndexOf("/"));

Try this;

string s = "http://localhost/portal/reportview.aspx";
string y = string.Format("{0}//{2}/{3}/",s.Split('/'));

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