石家庄建站平台

十年经验 优惠价格 贴心服务

服务热线 15383239821

C#获取当前页面的url

发布时间:2013-06-05    来源:

 

HttpContext.Current.Request.Url.PathAndQuery

1、通过ASP.NET获取
如果测试的url地址是http://www.idc311.com/testweb/default.aspx, 结果如下:
Request.ApplicationPath:                /testweb
Request.CurrentExecutionFilePath      /testweb/default.aspx
Request.FilePath:                       /testweb/default.aspx
Request.Path:                           /testweb/default.aspx
Request.PhysicalApplicationPath:        E:\WWW\testwebRequest.PhysicalPath:                   E:\WWW\testweb\default.aspx
Request.RawUrl:                         /testweb/default.aspx
Request.Url.AbsolutePath:               /testweb/default.aspx
Request.Url.AbsoluteUrl:                http://www.idc311.com/testweb/default.aspx
Request.Url.Host:                       http://www.idc311.com/
Request.Url.LocalPath:                  /testweb/default.aspx

2、通过JS获取

<table width=100% cellpadding=0 cellspacing=0 border=0 >

<script>

thisURL = document.URL;

thisHREF = document.location.href;

thisSLoc = self.location.href;

thisDLoc = document.location;

strwrite = "<tr><td valign=top>thisURL: </td><td>[" + thisURL + "]</td></tr>"

strwrite += "<tr><td valign=top>thisHREF: </td><td>[" + thisHREF + "]</td></tr>"

strwrite += "<tr><td valign=top>thisSLoc: </td><td>[" + thisSLoc + "]</td></tr>"

strwrite += "<tr><td valign=top>thisDLoc: </td><td>[" + thisDLoc + "]</td></tr>"

document.write( strwrite );

</script>

thisDLoc = document.location; <BR>

thisURL = document.URL; <BR>

thisHREF = document.location.href; <BR>

thisSLoc = self.location.href;<BR>

<script>

上一篇:C# 哈希表Hashtable的增加,删除,遍历,排序

下一篇:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误

还没开展互联网业务? 马上开始