簡體   English   中英

我該如何做,以便用戶可以登出網站?

[英]How do I make it so the user can log out of the website?

在我的網站上,用戶可以選擇注冊然后登錄,但是我想知道我該怎么做,以便用戶以后可以注銷。

c#代碼:這是登錄代碼。

 protected void Page_Load(object sender, EventArgs e)
        {
            lb_Fail.Visible = false;
        }

        protected void btn_Login_Click(object sender, EventArgs e)

        {
            // connecion to the database
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Fasthosts_MMConnectionString"].ConnectionString);

            SqlDataAdapter sda = new SqlDataAdapter("SELECT COUNT(*) FROM Fasthosts_Registration_MM WHERE username='" + tb_UsernameLogin.Text + "' AND password='" + tb_PasswordLogin.Text + "'", conn);
            /* in above line the program is selecting the whole data from table and the matching it with the user name and password provided by user. */
            DataTable dt = new DataTable(); //this is creating a virtual table  
            sda.Fill(dt);
            if (dt.Rows[0][0].ToString() == "1")
            {

                Response.Redirect("Domains.aspx");

            }
            else
            {
                lb_Fail.Text = ("Incorrect login details");
                lb_Fail.Visible = true;
            }
        }

如果創建一個注銷按鈕,我需要什么代碼。

您正在超越自己。 您實際上尚未登錄。 :)您所做的所有工作均已驗證其憑據正確。

有窗體身份驗證的例子在這里 有三個重要部分:

  1. 告訴IIS您正在使用表單身份驗證的web.config:
<authentication mode="Forms" />
  1. 登錄名(特別是FormsAuthentication.RedirectFromLoginPage() ,它指示登錄成功)
  2. 注銷:
FormsAuthentication.SignOut()

是的,如果您打算在互聯網上發布此問題,請解決您的SQL注入問題。 您可以在此處找到相關幫助(基本上,使用參數,而不是將用戶的文本放入SQL命令中)。

暫無
暫無

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

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