http://www.mystudy.cn/web/ind">

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

来源:这里教程网 时间:2026-02-21 13:13:26 作者:

本实例的测试url:http://www.mystudy.cn/web/index.aspx 

1、通过c#获取当前页面的url 

string url = Request.Url.AbsoluteUri; //结果: <a href="http://www.mystudy.cn/web/index.aspx" target="_blank">http://www.mystudy.cn/web/index.aspx</a>   
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

以上就是C#获取当前页面的URL示例代码的内容,更多相关内容请关注PHP中文网(www.php.cn)!

相关推荐