浏览器要求在每次登录时存储用户名和密码

时间:2013-10-01 17:06:11

标签: c# html asp.net google-chrome

更具体地说,Chrome。以下操作在Firefox,IE或Opera中发生。

当我登录时,收到提示,询问我是否允许浏览器存储用户的用户名和密码。但是,无论我从选项中选择什么(是的,从不为这个网站),如果我再次注销并重新登录,我会得到相同的提示。

我的登录表单的HTML如下:

    <form id="def_mainForm" runat="server">
<div id="loginContainer">
    <asp:Panel ID="pnlLog" runat="server" DefaultButton="btnLogSubmit">
        <div id="loginFormContainer">
            <div class="logGroup">
                <div class="logLabel boldFont">
                    Email / Username
                 </div>
                 <asp:TextBox ID="username" runat="server" CssClass="loginBoxes" ToolTip="Enter your email address or username here" />
             </div>
             <div class="logGroup">
                 <div class="logLabel boldFont">
                     Password
                 </div>
                 <asp:TextBox ID="password" runat="server" TextMode="Password" CssClass="loginBoxes" ToolTip="Enter your password here" />
                  <a href="respass.aspx" class="logLabel">Forgot your password?</a>
             </div>
             <div id="logButtonHolder">
                 <asp:Button ID="btnLogSubmit" runat="server" Text="Log in" CssClass="defButton" />
             </div>
        </div>
    </asp:Panel>
</div>

这样的代码隐藏看起来如此:

    void btnLogSubmit_Click(object sender, EventArgs e)
{
    this.validateUser(this.username.Text, this.password.Text, false);
}

void btn_gmb_OK_Click(object sender, EventArgs e)
{

}

private void validateUser(string email, string password, bool remember)
{
    Common.Validator validator = new Common.Validator(email, password);
    string response = "";
    int userId = -1;
    int personId = -1;
    bool valid = validator.Validate(out response, ref userId, ref personId);

    if (valid)
    {
        this.Session["gs_sessionId"] =  this.Session.SessionID;
        this.Session["gs_userId"] = userId;
        this.Session.Timeout = 60;
        HttpCookie remCookie = new HttpCookie("gsc_sessionId", this.Session["gs_sessionId"].ToString());
        remCookie.HttpOnly = true;

        if (remember)
            remCookie.Expires = DateTime.MaxValue;
        else
            remCookie.Expires = DateTime.Now.AddMinutes(60);

        Response.Cookies.Add(remCookie);

        gsWs.AddUserLogin(wsPass, userId, Request.UserHostAddress);
        this.Session["gs_person"] = gsWs.GetPersonByUserId(wsPass, userId).OuterXml;
        Response.Redirect("home.aspx");
    }
    else
    {

    }
}

我已经用Google搜索了这个问题,我只是遇到了希望通过“autocomplete = off”完全禁用此功能的人,添加哪些,我可能会添加,仍会导致同样的问题。

我错过了一些明显的东西吗?我做错了什么吗?您可以给予任何帮助或建议。非常感谢。

编辑:

以下是检查Cookie的代码:

    protected bool checkAlreadyLoggedIn()
{
    bool loggedIn = false;
    try
    {
        if ((Request.Cookies["gsc_sessionId"] != null) && (Request.Cookies["gsc_sessionId"].Value != ""))
        {
            this.Session["gs_sessionId"] = Request.Cookies["gsc_sessionId"].Value;
            loggedIn = true;
            Response.Redirect("home.aspx");
        }
        if (this.Session["gs_sessionId"] != null)
        {
            loggedIn = true;
            Response.Redirect("home.aspx");
        }
    }
    catch (Exception ex)
    {

    }
    return loggedIn;
}

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        if (!this.IsPostBack)
            if (!(this.checkAlreadyLoggedIn()))
                this.logUserOut(false);

    }
    catch (Exception ex)
    {

    }
}

protected void logUserOut(bool redirect)
{
    if (this.Session["gs_sessionId"] != null)
    {
        this.Session["gs_sessionId"] = null;
        this.Session.Abandon();
        Response.Cookies["gsc_sessionId"].Expires = DateTime.MinValue;
        Response.Cookies["gsc_sessionId"].Value = "";
        if (redirect)
            Response.Redirect("Default.aspx");
    }
    else
        if (redirect)
            Response.Redirect("Default.aspx");
}

0 个答案:

没有答案