- ///
- /// 获取完整的URL(带参数)
- ///
- ///
- public static string GetUrl()
- {
- return string.Format("http://{0}{1}", HttpContext.Current.Request.ServerVariables["HTTP_HOST"].ToString(), HttpContext.Current.Request.Url.PathAndQuery.ToString());
- }
- ///
- /// 获取URL的最后文件部分
- ///
- public static string GetUrlPath(string url)
- {
- return url.Substring(url.LastIndexOf("/"));
- }
- ///
- /// 返回URL中结尾的文件名
- ///
- public static string GetFilename(string url)
- {
- if (url == null) { return ""; }
- string[] strs1 = url.Split(new char[] { '/' });
- return strs1[strs1.Length - 1].Split(new char[] { '?' })[0];
- }
- ///
- /// 返回完全域名,带端口
- ///
- /// 来源URL
- ///
- public static string GetDomainUrl(string url)
- {
- string newUrl;
- //去掉 http://字符串
- newUrl = url.ToLower().Replace("\\", "/").Replace("http://", "");
- //只截取到第一个'/'符号的字符串
- if (newUrl.IndexOf('/') == -1)
- {
- newUrl = "http://" + newUrl; return newUrl;
- }
- newUrl = newUrl.Substring(0, newUrl.IndexOf('/'));
- newUrl = "http://" + newUrl;
- return newUrl;
- }