如此这般:using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string myurl = GetUrl(); Response.Write(myurl); } protected string GetUrl() { //取本页URL地址 string strTemp = ""; if (Request.ServerVariables["HTTPS"] == "off") { strTemp = "http://"; } else { strTemp = "https://"; }
strTemp = strTemp + Request.ServerVariables["SERVER_NAME"];
if (Request.ServerVariables["SERVER_PORT"] != "80") { strTemp = strTemp + ":" + Request.ServerVariables["SERVER_PORT"]; }
strTemp = strTemp + Request.ServerVariables["URL"];
if (Request.QueryString.ToString().Trim().Length!=0) { strTemp = strTemp + "?" + Request.QueryString; }
return strTemp; }}在js中只要一句:window.location.href不过要对url做更复杂的分析就不如.net灵活了
转载于:https://www.cnblogs.com/tuyile006/archive/2007/06/13/782055.html
相关资源:在asp.net中获取当前页面的URL的方法(推荐)