知识在于积累(.NET之路……)

导航

C#获取当前页面的URL地址

#region 获取页面地址
/// <summary>
/// 获取页面地址
/// </summary>
/// <returns></returns>
public static string GetUrl()
{
string strTemp = "http://";
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTPS"] == "off")
{
strTemp
= "http://";
}
else
{
strTemp
= "https://";
}

strTemp
= strTemp + System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"];

if (System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT"] != "80")
{
strTemp
= strTemp + ":" + System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
}

strTemp
= strTemp + System.Web.HttpContext.Current.Request.ServerVariables["URL"];

if (System.Web.HttpContext.Current.Request.QueryString.AllKeys.Length > 0)
{
strTemp
= strTemp + "?" + System.Web.HttpContext.Current.Request.QueryString;
}

return strTemp;
}
#endregion

posted on 2010-10-25 11:05  汤尼  阅读(904)  评论(1编辑  收藏  举报