For example: Http://www.abc.com/book/list.aspx, the corresponding fetch to list.aspx. Generally we can write this:
Copy Code code as follows:
String url = Request.Url.ToString ();
string r = URL. Substring (URL. LastIndexOf ('/') + 1);
Response.Write (R);
The above method is generally acceptable, but there may be a problem if the URL takes a parameter. With Id=3&name=tim, for example, the last thing you get is list.aspx?id=3&name=tim, which is obviously more than just a filename.
As a matter of fact. The URI class provides a segments property that is essentially a string array object that holds the values of the URL path segment, and the last element is the filename.
Copy Code code as follows:
Response.Write (Request.url.segments[request.url.segments.length-1]);
You can experiment, even if the file name is followed by a parameter? Id=3&name=tim, the final gain is still list.aspx.