如此这般:
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灵活了