[英]How to redirect other page after successfully login by a class on WCF
我有一個WCF,上面有我的課程。(作為示例登錄類)
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.