我有这种方法从字符串URI中获取文件名.我该怎么做才能让它更健壮?
private string GetFileName(string hrefLink)
{
string[] parts = hrefLink.Split('/');
string fileName = "";
if (parts.Length > 0)
fileName = parts[parts.Length - 1];
else
fileName = hrefLink;
return fileName;
}
Run Code Online (Sandbox Code Playgroud) 我想写ac#方法来检索当前页面.例如Default6.aspx我知道我可以做以下事情:
string url = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost:1302/TESTERS/Default6.aspx
string path = HttpContext.Current.Request.Url.AbsolutePath;
// /TESTERS/Default6.aspx
string host = HttpContext.Current.Request.Url.Host;
// localhost
Run Code Online (Sandbox Code Playgroud)
但是我如何获得Default6.aspx?如果url是http:// localhost:1302/TESTERS /,我的方法应该返回default.aspx