簡體   English   中英

如何將值從窗體窗體應用發送到asp.net服務器並從中獲取值窗體數據庫?

[英]how to send values form the window form appliction to an asp.net server and get the values form database from there?

我希望用戶在Windows窗體中獲取用戶名和密碼,然后將其發送到Web窗體進行驗證,然后在從數據庫中進行驗證之后,將條目(由用戶聯合完成的課程)發送回窗口窗體,我搜索了很多,但是找不到任何合適的方法,我是新的ti c#和asp.net。。我在這里找到了一種放置代碼的方法,請告訴我有沒有更好的方法來完成我的工作。期望值我得到了整個html代碼,因此我習慣將期望值封裝在服務器端的html標記中,而在客戶端,我正在使用正則表達式獲得這些值。這是Windows的代碼,在從文字框

 try
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://localhost:50612/Inclusive_LMS/speech/login.aspx/?stdId=" +tb_stdId.Text + "&pass=" + tb_pass.Text);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string content = new StreamReader(response.GetResponseStream()).ReadToEnd();

            Match valid = Regex.Match(content, @"(?<=(<span[^>]*>))([^<]*)(?=(</span>))");

            if (valid.Success)
            {
                this.Hide();
                Student_dashboard ins = new Student_dashboard();
                ins.Show();
            }
            else
            {
                MessageBox.Show("invalid user Id or password");

            }


           // textBox2.Text = "" + content + "";
        }
        catch (Exception ex)
        {
            MessageBox.Show("check your internet connection, failed to connect the server.");

        }

這是“ http:// localhost:50612 / Inclusive_LMS / speech / login.aspx ”頁面的代碼,在設計者方面,我在html頁面上只有一個標簽

    SqlDataReader r;
    SqlCommand cmd = new SqlCommand("Select * from Student where Std_Id='" +Convert.ToInt32(Request.QueryString["stdId"]) + "' and Password='" +Request.QueryString["pass"]+ "'", con);
   try
   {
    con.Open();
        r = cmd.ExecuteReader();
        if (r.Read())
            Label1.Text = "success";
        else
            Label1.Text = "fail";
        con.Close();
     }
      catch
      {
          Label1.Text = "error";
      }

我猜,最好的方法是直接從Windows應用程序(如果可能)訪問數據庫以執行任何任務。

如果無法直接訪問數據庫,則可以在webform項目中創建一個Web服務,然后在winforms應用程序中使用它。 這很容易實現並且效果很好。

第三種方法是使用ASP.NET框架中的WebAPI來完成此任務。

您需要選擇最適合您的方案。 祝你好運!

更新:訪問ASP.NET官方網站以獲取大量資源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM