2013年9月25日 星期三

取得前頁網址,取得目前網址

取得前頁網址


Request.UrlReferrer.AbsolutePath
'結果如下
'/test.asp
Request.UrlReferrer.ToString()
'結果如下
'http:www.abc.com/test.asp


取得目前網址

public partial class getCurrentUri : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
   {
        if (!IsPostBack)
        {          
            //http://msdn2.microsoft.com/zh-tw/library/system.uri(VS.80).aspx            
            Uri uri = Request.Url;     
  
            Response.Write("Request.Url.OriginalString : " + uri.OriginalString + "<br/>");
            Response.Write("Request.Url.AbsoluteUri : " + uri.AbsoluteUri + "<br/>");          
            Response.Write("Request.Url.Scheme : " + uri.Scheme + "<br/>");
            Response.Write("Request.Url.Host : " + uri.Host + "<br/>");
            Response.Write("Request.Url.Authority : " + uri.Authority + "<br/>");
            Response.Write("Request.Url.Port : " + uri.Port + "<br/>");
            Response.Write("Request.Url.PathAndQuery : " + uri.PathAndQuery + "<br/>");
            Response.Write("Request.Url.AbsolutePath : " + uri.AbsolutePath + "<br/>");          
            Response.Write("Request.Url.Query : " + uri.Query + "<br/>");
            Response.Write("Request.QueryString : " + Request.QueryString.ToString() + "<br/>");
            Response.Write("Request.UserHostAddress : " + Request.UserHostAddress + "<br/>");
            Response.Write("Request.UserHostName : " + Request.UserHostName + "<br/>");
        }
    }
}

沒有留言:

張貼留言