当前位置: 移动技术网 > IT编程>开发语言>.net > C#获取当前页面的URL示例代码

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

2017年12月12日  | 移动技术网IT编程  | 我要评论
本实例的测试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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网