For example: http://www.abc.com/book/list.aspx, you must obtain list.aspx. Generally, we can write as follows:
CopyCodeThe Code is 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 is a problem if the URL address contains parameters. For example, add? Id = 3 & name = Tim, then the final result is list. aspx? Id = 3 & name = Tim, apparently not only the file name.
In fact, the. Uri class provides a segments attribute. Its essence is a string array object that stores the values of URL path segments. The last element is the file name.Copy codeThe Code is as follows: Response. Write (request. url. segments [request. url. segments. Length-1]);
Can you try it out, even if the file name is followed by a parameter? Id = 3 & name = Tim. The final result is still list. aspx.