正确的方法是:HttpContext.Current.Request.Url.PathAndQuery
Request.Url.PathAndQuery
string 类型。等于 Request.Url.AbsolutePath 和 Request.Url.Query 相加。
Request.Url.AbsolutePath
string 类型。指当前页面 URL 的绝对路径,不包括查询字符串部分。
示例:/test/Default.aspx
Request.Url.Query
string 类型。指当前页面 URL 的查询字符串,从“?”开始。
示例:?a=1&b=2
1、通过ASP.NET获取
如果测试的url地址是http://www.test.com/testweb/default.aspx, 结果如下:
Request.ApplicationPath: /testweb
Request.CurrentExecutionFilePath: /testweb/default.aspx
Request.FilePath: /testweb/default.aspx
Request.Path: /testweb/default.aspx
Request.PhysicalApplicationPath: E:\WWW\testwebRequest.PhysicalPath: E:\WWW\testweb\default.aspx
Request.RawUrl: /testweb/default.aspx
Request.Url.AbsolutePath: /testweb/default.aspx
Request.Url.AbsoluteUrl: http://www.test.com/testweb/default.aspx
Request.Url.Host: www.test.com
Request.Url.LocalPath: /testweb/default.aspx
URL http://localhost:1897/News/Press/Content.aspx/123?id=1#toc
Request.ApplicationPath /
Request.PhysicalPath D:\Projects\Solution\web\News\Press\Content.aspx
System.IO.Path.GetDirectoryName(Request.PhysicalPath) D:\Projects\Solution\web\News\Press
Request.PhysicalApplicationPath D:\Projects\Solution\web\
System.IO.Path.GetFileName(Request.PhysicalPath) Content.aspx
Request.CurrentExecutionFilePath /News/Press/Content.aspx
Request.FilePath /News/Press/Content.aspx
Request.Path /News/Press/Content.aspx/123
Request.RawUrl /News/Press/Content.aspx/123?id=1
Request.Url.AbsolutePath /News/Press/Content.aspx/123
Request.Url.AbsoluteUri http://localhost:1897/News/Press/Content.aspx/123?id=1
Request.Url.Scheme http
Request.Url.Host localhost
Request.Url.Port 1897
Request.Url.Authority localhost:1897
Request.Url.LocalPath /News/Press/Content.aspx/123
Request.PathInfo /123
Request.Url.PathAndQuery /News/Press/Content.aspx/123?id=1
Request.Url.Query ?id=1
Request.Url.Fragment
Request.Url.Segments
/
News/
Press/
Content.aspx/
123
2、通过JS获取
================= 获取IP 1、ASP.NET中获取 获取服务器的IP地址: using System.Net; string myIP,myMac; System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList; if ( addressList.Length>1) { myIP = addressList[0].ToString(); myMac = addressList[1].ToString(); } else { myIP = addressList[0].ToString(); myMac = "没有可用的连接"; } myIP地址就是服务器端的ip地址。 获取客户端的ip地址,可以使用 //获取登录者ip地址 string ip = Request.ServerVariables["REMOTE_ADDR"].ToString(); 2、通过JS获取 回答2:
恩 你用的URL传的话是 xxxx.aspx?pname=xxxx 这样的吗? 回答3:
Page.Server.Transfer("xxxx.aspx?pname="+value); 相关问答
最新问答
|