replace url from the method C# RRS feed

  • Question

  • method authorization forming url
    I want to insert a link (result) from  method autorization in class Form_WinForm_1, in line "this.web_Browser.Url" in return url -
    I'm new to C#, can you guys give me a hand with this?

    namespace WinForm
        partial class Form_WinForm_1
            private System.ComponentModel.IContainer components = null;
            protected override void Dispose(bool disposing)
                if (disposing && (components != null))
            private void InitializeComponent()
                this.web_Browser.Location = new System.Drawing.Point(0, 60);
                this.web_Browser.MinimumSize = new System.Drawing.Size(20, 20);
                this.web_Browser.Name = "web_Browser";
                this.web_Browser.ScriptErrorsSuppressed = true;
                this.web_Browser.Size = new System.Drawing.Size(1200, 800);
                this.web_Browser.Url = new System.Uri("", System.UriKind.Absolute);
                this.web_Browser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.web_Browser_DocumentCompleted);

    static void autorization(string[] args)
            Uri address = new Uri("");
            ServicePointManager.ServerCertificateValidationCallback += delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
            using (WebClient webClient = new WebClient())
                webClient.QueryString.Add("login", "login");
                webClient.QueryString.Add("pass", "pass");
                string result = webClient.DownloadString(address);

    Wednesday, June 6, 2018 2:04 PM

All replies

  • Not sure I really follow but I'm guessing that you want to get the result from authorization back to the calling method?

    //Not really sure where this resides in your code
    static string authorization ( string[] args )
       return result;

    If you want to combine that with some URL then you'll have to decide how they go together but string concatenation or string interpolation will allow you to combine them together.

    //String concat
    url = "https://www.google.com" + searchQuery;
    //Or string interpolation
    url = $"https://www.google.com{searchQuery}";

    Also note that you posted the contents of the designer.cs file. You should never edit this file. It is auto generated and anything you put in here will get wiped. All your code goes in the root .cs file (e.g. Form_Winform_1.cs). Also, do not change anything in InitializeComponent or modify the generated constructor of the form. IC is called whenever your form is created (whether it is displayed or not) and includes in the designer. Whatever changes are made in the IC method are ultimately saved back to the auto-generated code so it'll mangle your results. Move any logic to manipulate the URL to the OnLoad virtual method.

    //This is in Form_Winform_1.cs
    //Do not ever edit the .designer.cs file
    public partial class Form_WinForm_1 : Form
       public Form_WinForm_1 ()
       protected override OnLoad ( EventArgs e )
          //Do any changes here
          var result = ...
          web_Browser.Url = $"http://www.google.com?{result}";

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, June 6, 2018 4:57 PM