C#获取当前页面的URL示例代码
(编辑:jimmy 日期: 2025/5/14 浏览:3 次 )
本实例的测试URL:http://www.mystudy.cn/web/index.aspx
1、通过C#获取当前页面的URL
复制代码 代码如下:
string url = Request.Url.AbsoluteUri; //结果: http://www.mystudy.cn/web/index.aspx
string host = Request.Url.Host; //结果:www.mystudy.cn
string rawUrl = Request.RawUrl; //结果:/web/index.aspx
string localPath = Request.Url.LocalPath; //结果:/web/index.aspx
2、通过Javascript获取当前页面的URL
复制代码 代码如下:
var url = document.URL; //结果:http://www.mystudy.cn/web/index.aspx
var href = document.location.href; //结果:http://www.mystudy.cn/web/index.aspx
var host = location.hostname; //结果:www.mystudy.cn
1、通过C#获取当前页面的URL
复制代码 代码如下:
string url = Request.Url.AbsoluteUri; //结果: http://www.mystudy.cn/web/index.aspx
string host = Request.Url.Host; //结果:www.mystudy.cn
string rawUrl = Request.RawUrl; //结果:/web/index.aspx
string localPath = Request.Url.LocalPath; //结果:/web/index.aspx
2、通过Javascript获取当前页面的URL
复制代码 代码如下:
var url = document.URL; //结果:http://www.mystudy.cn/web/index.aspx
var href = document.location.href; //结果:http://www.mystudy.cn/web/index.aspx
var host = location.hostname; //结果:www.mystudy.cn
下一篇:Silverlightbutton图片切换样式实例代码