簡體   English   中英

WCF上的類成功登錄后如何重定向其他頁面

[英]How to redirect other page after successfully login by a class on WCF

  • 我有一個WCF,上面有我的課程。(作為示例登錄類)

    • 並且我還有一個使用C#的其他應用程序,我希望用戶可以使用WCF Login類通過該應用程序登錄,並且用戶在成功登錄后重定向到其他頁面。 謝謝幫助我。
    • 以及如何定義異常消息? 在課堂還是App?

WCF服務的登錄類:

public class Service1 : IService1
    {
        public bool UserLogin(Login userL)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["BCSConnectionString"].ConnectionString;
            con.Open();
            bool result = false;
            string Message;
            using (SqlCommand cmd = new SqlCommand("SELECT Username,Password FROM Users where Username=@Username and Password=@Password", con))
            {
                cmd.Parameters.AddWithValue("@Username", userL.Username);
                cmd.Parameters.AddWithValue("@Password", userL.Password);
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
                con.Close();
            }
            return result;
        }

其他應用背后的代碼

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        ServiceReference1.Service1Client objServiceClientobjService = new ServiceReference1.Service1Client();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Login UserLogin = new Login();
            textBox1.Text = UserLogin.Username;
            textBox1.Text = UserLogin.Password;

        }
    }
}

在您的按鈕中嘗試此代碼button1_Click();

   Login UserLogin = new Login();
   UserLogin.Username = textBox1.Text;
   UserLogin.Password = textBox2.Text;
   if(objServiceClientobjService.UserLogin(UserLogin))
         {
               Response.Redirect("Home.html"); // your page to go after valid user login
         }
     else
         {
             // show error code
         }

暫無
暫無

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

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