About the C.net winform program validating the integrated authentication instance of moss

  • 2020-05-09 19:10:28
  • OfStack

Recently, the development of vsto program needs to upload documents to moss platform. Because the website USES windows integrated authentication, we have encountered the permission problem and need to enter the password. It makes the operation and user experience very inconvenient. After studying for a long time and not finding a good method, I finally got the following method. My understanding of the principle should be to simulate the message sent by IE for verification, and the problem of login can be realized.

Note: COM references with names Microsoft XML, V2.6 and above need to be added



 private void button3_Click(object sender, EventArgs e)
        {

            this.textBox1.Text=@"http://localhost/Default.aspx";       // The url or path of authentication 
            this.textBox2.Text="spsservice";                             // Account name 
            this.textBox3.Text = "Zd$1234";                              // password 

            MSXML2.XMLHTTP http = new MSXML2.XMLHTTP();

            http.open("post", this.textBox1.Text, false, this.textBox2.Text, this.textBox3.Text);
            http.send("");
            switch (http.status)
            {
                case 200:
                    {
                        MessageBox.Show(" Login successful! ");
                        break;
                    }
                case 401:
                    {
                        MessageBox.Show(" Username and password error ");
                        break;
                    }
                default:
                    {
                        MessageBox.Show(" Connection failed, please try again ");
                        break;
                    }


Related articles: