简体   繁体   English

由于用户不存在/密码/用户名正确而导致尝试登录网站失败时如何返回消息?

[英]How to return a message when a try to login to the website failed, because the user does not exist/password/username arent correct?

I built a website as my project for school. 我建立了一个网站作为我的学校项目。 I built a registration system, but I have a problem: I want the user to recive a message from the server when the login proccess fails, and everything goes right, except from the message. 我建立了一个注册系统,但是有一个问题:我希望用户在登录过程失败时从服务器接收一条消息,并且一切正常,除了该消息。 Somehow, though everything is right, the user doesnt get any message from the server at all. 无论如何,尽管一切正常,但用户根本没有从服务器收到任何消息。 He is only redirected, as the code is programmed. 仅当代码被编程时,他才被重定向。 I followed the course of events and it seems that it should show a message, but in reality its not. 我遵循事件的过程,似乎它应该显示一条消息,但实际上它不是。

Im using aspx. 我正在使用aspx。

MasterPage.aspx: MasterPage.aspx:

<section>
<table id='tblog' border='0'>
    <%=hello %>
    <%=logIn %>
    <%=topPanel %>
    <%=msgError %>
    </table>
</section>

MasterPage.aspx.cs MasterPage.aspx.cs

public string msgError = "";
if  (Request.Form["submit1"] != null)
{

    nameen = Request.Form["nameen"];
    password  = Request.Form["password"];

    query = "select * from Users";
    query += " WHERE Name  = '" + nameen + "'";
    query += " AND PWD  = '" + password + "'";


    SqlDataReader data = DalBll.DataReadSQL(DalBll.GetConnection(), query);
    if (data.Read())
    {
        ///(I DELETED THIS PART)
    }
    else
    {
        msgError += "<tr><td colspan='2'><div>WRONG PASSWORD/USERNAME</div></td></tr>";
    }
    Response.Redirect("Default.aspx");
}

There are many documented ways to display information to the user. 有许多记录的方法可以向用户显示信息。 One way to do this is to use a javascript alert. 一种方法是使用javascript警报。

Replace Response.Redirect() with this: 用以下内容替换Response.Redirect()

ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + msgError + "');", true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我再次尝试插入用户名密码时,错误消息不会消失 - The error message does not go away when I try again to insert username password 用户“用户名”的登录失败 - Login failed for user 'username' 使用Dynamics GP用户名和密码的SqlConnection-用户登录失败 - SqlConnection using Dynamics GP username and password — Login failed for user 输入正确的用户名和密码后,ASP登录无法正常工作 - ASP login doesn't work when correct username and password are entered 限制登录时如何向用户返回正确的错误消息 - How to return correct error message to User when log in is restricted 用户单击网站链接时自动填写用户名+密码 - Auto fill-in username + password when user clicks a website link 如何更改仅适用于正确用户的存储在文本文件中的用户名和密码 - how to change a username and password stored in a text file only for the correct user “用户名或密码不正确” - 收到相同的消息 - "Username or Password is not correct" - getting the same message 如果用户输入正确的用户名和密码,我想从login.aspx重定向到address.aspx - I want to redirect from login.aspx to address.aspx if the user insert the correct username and password 如何修复“用户&#39;Username.sql&#39;登录失败。”? - How do I fix “Login failed for user 'Username.sql'.”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM