介绍一下ASP.NET取得当前页面的完整URL 的方放

来源:互联网 发布:axure 8.0 mac 破解版 编辑:程序博客网 时间:2024/06/05 03:12
[csharp] view plaincopy01.private string GetPath()  02.    {  03.        string strPath = "http://" + Request.ServerVariables["HTTP_HOST"] + Request.ServerVariables["PATH_INFO"] + "?" + Request.ServerVariables["QUERY_STRING"];  04.        if(strPath.EndsWith("?"))  05.        {  06.            strPath = strPath.Substring(0, strPath.Length - 1);  07.        }  08.        return strPath;  09.    }   asp.net获取URL和IP地址 HttpContext.Current.Request.Url.ToString() 并不可靠。如果当前URL为 http://localhost/search.aspx?user=http://csharp.xdowns.com&tag=%BC%BC%CA%F5通过HttpContext.Current.Request.Url.ToString()获取到的却是 http://localhost/search.aspxuser=http://csharp.xdowns.com&tag=¼¼Êõ正确的方法是:HttpContext.Current.Request.Url.PathAndQuery1、通过ASP.NET获取 如果测试的url地址是http://www.test.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.test.com/testweb/default.aspx Request.Url.Host:                       http://www.test.com/ Request.Url.LocalPath:                   /testweb/default.aspx 2、通过JS获取 [javascript] view plaincopy01.<table width=100% cellpadding=0 cellspacing=0 border=0 >  02.  03.<script>   04.  05.thisURL = document.URL;   06.  07.thisHREF = document.location.href;   08.  09.thisSLoc = self.location.href;   10.  11.thisDLoc = document.location;   12.  13.strwrite = "<tr><td valign=top>thisURL: </td><td>[" + thisURL + "]</td></tr>"   14.  15.strwrite += "<tr><td valign=top>thisHREF: </td><td>[" + thisHREF + "]</td></tr>"  16.  17.strwrite += "<tr><td valign=top>thisSLoc: </td><td>[" + thisSLoc + "]</td></tr>"  18.  19.strwrite += "<tr><td valign=top>thisDLoc: </td><td>[" + thisDLoc + "]</td></tr>"  20.  21.document.write( strwrite );   22.  23.</script>   24.  25.thisDLoc = document.location; <BR>  26.  27.thisURL = document.URL; <BR>  28.  29.thisHREF = document.location.href; <BR>  30.  31.thisSLoc = self.location.href;<BR>  32.  33.<script>   34.  35.thisTLoc = top.location.href;   36.  37.thisPLoc = parent.document.location;   38.  39.thisTHost = top.location.hostname;   40.  41.thisHost = location.hostname;   42.  43.strwrite = "<tr><td valign=top>thisTLoc: </td><td>[" + thisTLoc + "]</td></tr>"  44.  45.strwrite += "<tr><td valign=top>thisPLoc: </td><td>[" + thisPLoc + "]</td></tr>"  46.  47.strwrite += "<tr><td valign=top>thisTHost: </td><td>[" + thisTHost + "]</td></tr>"  48.  49.strwrite += "<tr><td valign=top>thisHost: </td><td>[" + thisHost + "]</td></tr>"  50.  51.document.write( strwrite );   52.  53.</script>   54.  55.thisTLoc = top.location.href; <BR>  56.  57.thisPLoc = parent.document.location; <BR>  58.  59.thisTHost = top.location.hostname; <BR>  60.  61.thisHost = location.hostname;<BR>  62.  63.<script>   64.  65.tmpHPage = thisHREF.split( "/" );   66.  67.thisHPage = tmpHPage[ tmpHPage.length-1 ];   68.  69.tmpUPage = thisURL.split( "/" );   70.  71.thisUPage = tmpUPage[ tmpUPage.length-1 ];   72.  73.strwrite = "<tr><td valign=top>thisHPage: </td><td>[" + thisHPage + "]</td></tr>"  74.  75.strwrite += "<tr><td valign=top>thisUPage: </td><td>[" + thisUPage + "]</td></tr>"  76.  77.document.write( strwrite );   78.  79.</script><tr><td>  

0 0