网络编程
位置:首页>> 网络编程>> ASP.NET>> 获取当前url

获取当前url

  发布时间:2024-05-09 09:04:30 

标签:获取当前url

如:http://localhost/newurl/WebForm1.aspx
1.方法document.URL(注意大小写)
结果是:http://localhost/newurl/WebForm1.aspx

2.HttpContext.Current.Request.Url.ToString(),
结果:http://localhost/newurl/WebForm1.aspx

3.HttpContext.Current.Request.Url.PathAndQuery;
结果:/newurl/WebForm1.aspx

备注:
如果当前URL为
http://localhost/search.aspx?user=tinyfool&tag=%BC%BC%CA%F5
通过HttpContext.Current.Request.Url.ToString()获取到的却是
http://localhost/search.aspx?user=tinyfool&tag=¼¼Êõ
这显然不对,怎么办?用HttpContext.Current.Request.Url.PathAndQuery好了,这个得到的正确的。:)

4.Javascript取url值 
刚写的一个小实例.实际中使用还是蛮多的.

<script language=javascript>  var str_url,str_pos,str_para;  var arr_param=new Array();  str_url = window.location.href;  str_pos = str_url.indexOf("?");  str_para = str_url.substring(str_pos+1);  if (str_pos>0){  arr_param=str_para.split("&amp;");  for(var i=0;i


0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com