2012-10-23 145 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