当前位置: 首页 > 新闻动态 > 软件编程

C#获取当前页面的URL示例代码

作者:用户投稿 浏览: 发布日期:2026-01-16
[导读]:获取当前页面的URL在某些情况下还是比较使用的,下面为大家介绍下如何通过C#以及Javascript获取当前页面的URL,感兴趣的朋友不要错过
本实例的测试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
免责声明:转载请注明出处:http://m.lexweb.cn/news/223821.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!