0

I'm trying to check the current web address of a webform.

I'm currently navigating to this new page by

webBrowser1.Document.GetElementById("id").InvokeMember("click");

I would like to get the url from the form, I know I could do this by a web browser.

user2839067
  • 11
  • 1
  • 5
  • Possible duplicate of [How to get the URL of the current page in C#](https://stackoverflow.com/questions/593709/how-to-get-the-url-of-the-current-page-in-c-sharp) – CodeNotFound May 14 '18 at 15:15
  • Possible duplicate of [Get URL of ASP.Net Page in code-behind from another page](https://stackoverflow.com/questions/651127/get-url-of-asp-net-page-in-code-behind-from-another-page) – AussieJoe May 14 '18 at 15:16

2 Answers2

0

Handle DocumentCompleted event of WebBrowser and check Url propertty of WebBrowserDocumentCompletedEventArgs parameter.

Sandeep
  • 333
  • 2
  • 7
0

So are you doing this in WinForms or Web Forms?

It looks like the former, so, to get the URL or action attribute value from a <form> using a WebBrowser would be the following:

    var form = webBrowser1.Document.GetElementById("ID");
    var actionurl = form.GetAttribute("action");

But, if you literally want the URL of the document, then it's just:

var url = webBrowser1.Document.Url;
Billy
  • 81
  • 2
  • 10