【问题标题】:Get the current Url of web browser in C#在 C# 中获取 Web 浏览器的当前 URL
【发布时间】:2012-10-23 16:49:39
【问题描述】:

如何在文本框中获取当前 url(在网络浏览器中打开的 url)?

例如:

webBrowser1.Url=new Uri("http://stackoverflow.com");

我的浏览器打开了链接!!

现在我想在文本框中获取 url (http://stackoverflow.com)

问候。

【问题讨论】:

    标签: c#


    【解决方案1】:
    yourTextBox.Text = webBrowser1.Url.ToString();
    

    【讨论】:

    • 是的!它很好,但你必须等到网络浏览器加载 url 否则你会得到一个错误......谢谢!
    【解决方案2】:
    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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 2014-05-07
      • 2015-08-09
      • 2011-06-24
      • 2011-01-18
      • 1970-01-01
      相关资源
      最近更新 更多