"www.test.com"是域名
"aaa"是站点名
"bbb.aspx"是页面名(文件名)
"id=5&name=kelli"是参数
【1】获取 完整url (协议名+域名+站点名+文件名+参数)
string url=Request.Url.ToString();
url= http://www.test.com/aaa/bbb.aspx?id=5 &name=kelli
【2】获取 站点名+页面名+参数:
string url=Request.RawUrl;
(或 string url=Request.Url.PathAndQuery;)
url= /aaa/bbb.aspx?id=5&name=kelli
【3】获取 站点名+页面名:
string url=HttpContext.Current.Request.Url.AbsolutePath;
(或 string url= HttpContext.Current.Request.Path;)
url= aaa/bbb.aspx
【4】获取 域名:
string url=HttpContext.Current.Request.Url.Host;
url= www.test.com
【5】获取 参数:
string url= HttpContext.Current.Request.Url.Query;
url= ?id=5&name=kelli
"aaa"是站点名
"bbb.aspx"是页面名(文件名)
"id=5&name=kelli"是参数
【1】获取 完整url (协议名+域名+站点名+文件名+参数)
string url=Request.Url.ToString();
url= http://www.test.com/aaa/bbb.aspx?id=5 &name=kelli
【2】获取 站点名+页面名+参数:
string url=Request.RawUrl;
(或 string url=Request.Url.PathAndQuery;)
url= /aaa/bbb.aspx?id=5&name=kelli
【3】获取 站点名+页面名:
string url=HttpContext.Current.Request.Url.AbsolutePath;
(或 string url= HttpContext.Current.Request.Path;)
url= aaa/bbb.aspx
【4】获取 域名:
string url=HttpContext.Current.Request.Url.Host;
url= www.test.com
【5】获取 参数:
string url= HttpContext.Current.Request.Url.Query;
url= ?id=5&name=kelli
ASP.Net C#代码处
string filePath = @"E:\Randy0528\中文目录\JustTest.rar";
Response.Write("文件路径:"+filePath);
Response.Write("更改路径字符串的扩展名。");
Response.Write(System.IO.Path.ChangeExtension(filePath, "txt"));
Response.Write("返回指定路径字符串的目录信息。。");
Response.Write(System.IO.Path.GetDirectoryName(filePath));
Response.Write("返回指定的路径字符串的扩展名。");
Response.Write(System.IO.Path.GetExtension(filePath));
Response.Write("返回指定路径字符串的文件名和扩展名。");
Response.Write(System.IO.Path.GetFileName(filePath));
Response.Write("返回不具有扩展名的指定路径字符串的文件名。");
Response.Write(System.IO.Path.GetFileNameWithoutExtens ion(filePath));
Response.Write("获取指定路径的根目录信息。");
Response.Write(System.IO.Path.GetPathRoot(filePath));
Response.Write("返回随机文件夹名或文件名。");
Response.Write(System.IO.Path.GetRandomFileName());
Response.Write("创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。");
Response.Write(System.IO.Path.GetTempFileName());
Response.Write("返回当前系统的临时文件夹的路径。");
Response.Write(System.IO.Path.GetTempPath());
Response.Write("确定路径是否包括文件扩展名。");
Response.Write(System.IO.Path.HasExtension(filePath));
Response.Write("获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。");
string filePath = @"E:\Randy0528\中文目录\JustTest.rar";
Response.Write("文件路径:"+filePath);
Response.Write("更改路径字符串的扩展名。");
Response.Write(System.IO.Path.ChangeExtension(filePath, "txt"));
Response.Write("返回指定路径字符串的目录信息。。");
Response.Write(System.IO.Path.GetDirectoryName(filePath));
Response.Write("返回指定的路径字符串的扩展名。");
Response.Write(System.IO.Path.GetExtension(filePath));
Response.Write("返回指定路径字符串的文件名和扩展名。");
Response.Write(System.IO.Path.GetFileName(filePath));
Response.Write("返回不具有扩展名的指定路径字符串的文件名。");
Response.Write(System.IO.Path.GetFileNameWithoutExtens
Response.Write("获取指定路径的根目录信息。");
Response.Write(System.IO.Path.GetPathRoot(filePath));
Response.Write("返回随机文件夹名或文件名。");
Response.Write(System.IO.Path.GetRandomFileName());
Response.Write("创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。");
Response.Write(System.IO.Path.GetTempFileName());
Response.Write("返回当前系统的临时文件夹的路径。");
Response.Write(System.IO.Path.GetTempPath());
Response.Write("确定路径是否包括文件扩展名。");
Response.Write(System.IO.Path.HasExtension(filePath));
Response.Write("获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。");
Response.Write(System.IO.Path.IsPathRooted(filePath));
执行结果
文件路径:E:\Randy0528\中文目录\JustTest.rar
更改路径字符串的扩展名。
E:\Randy0528\中文目录\JustTest.txt
返回指定路径字符串的目录信息。。
E:\Randy0528\中文目录
返回指定的路径字符串的扩展名。
.rar
返回指定路径字符串的文件名和扩展名。
JustTest.rar
返回不具有扩展名的指定路径字符串的文件名。
JustTest
获取指定路径的根目录信息。
E:\
返回随机文件夹名或文件名。
ct2h5b2h.sed
创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。
C:\Documents and Settings\Randy\Local Settings\Temp\tmpAD.tmp
返回当前系统的临时文件夹的路径。
C:\Documents and Settings\Randy\Local Settings\Temp\
确定路径是否包括文件扩展名。
True
获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。
True
执行结果
文件路径:E:\Randy0528\中文目录\JustTest.rar
更改路径字符串的扩展名。
E:\Randy0528\中文目录\JustTest.txt
返回指定路径字符串的目录信息。。
E:\Randy0528\中文目录
返回指定的路径字符串的扩展名。
.rar
返回指定路径字符串的文件名和扩展名。
JustTest.rar
返回不具有扩展名的指定路径字符串的文件名。
JustTest
获取指定路径的根目录信息。
E:\
返回随机文件夹名或文件名。
ct2h5b2h.sed
创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。
C:\Documents and Settings\Randy\Local Settings\Temp\tmpAD.tmp
返回当前系统的临时文件夹的路径。
C:\Documents and Settings\Randy\Local Settings\Temp\
确定路径是否包括文件扩展名。
True
获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。
True