C#获取当前页面的URL

来源:互联网 发布:企业社保报盘软件 编辑:程序博客网 时间:2024/06/10 21:44

本实例的测试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.cnstring rawUrl = Request.RawUrl;              //结果:/web/index.aspxstring localPath = Request.Url.LocalPath;    //结果:/web/index.aspx

2、通过Javascript获取当前页面的URL

var url = document.URL;             //结果:http://www.mystudy.cn/web/index.aspxvar href = document.location.href;  //结果:http://www.mystudy.cn/web/index.aspxvar host = location.hostname;       //结果:www.mystudy.cn