获取当前url
更新时间:2006年08月24日 00:00:00 作者:
如: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值
刚写的一个小实例.实际中使用还是蛮多的.
[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
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值
刚写的一个小实例.实际中使用还是蛮多的.
[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
相关文章
ASP.NET MVC中_ViewStart.cshtml作用介绍
这篇文章介绍了ASP.NET MVC中_ViewStart.cshtml的作用,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2022-03-03
.net 6精简版webapi教程及热重载、代码自动反编译演示
这篇文章介绍了.net 6精简版webapi教程及热重载、代码自动反编译演示,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2021-12-12


最新评论