2012-10-23 142 views
2

如何在文本框中獲取當前網址(網頁瀏覽器中打開的網址)?獲取C#中網頁瀏覽器的當前網址

例如:

webBrowser1.Url =新URI( 「http://stackoverflow.com」);

和我的瀏覽器打開鏈接!

現在我想在文本框中

關於獲得url(http://stackoverflow.com)。

回答

1
Result : http://localhost:1302/TESTERS/Default6.aspx 
string url = HttpContext.Current.Request.Url.AbsoluteUri; 

result : /TESTERS/Default6.aspx 
string path = HttpContext.Current.Request.Url.AbsolutePath; 


result : localhost 
string host = HttpContext.Current.Request.Url.Host; 
7
yourTextBox.Text = webBrowser1.Url.ToString(); 
+0

是的!它的好,但你必須等到網頁瀏覽器加載的網址,否則你會得到一個錯誤...謝謝! – user1509283