【问题标题】:How to turn autocomplete off and prevent pre-population of a field如何关闭自动完成功能并防止预先填充字段
【发布时间】:2017-09-12 16:45:19
【问题描述】:

如何防止我的用户名和密码 ASP.NET/C# TextBox 字段在 Chrome 中预填充,即使 Google Smart Lock 已保存它。

我可以进入 Google 设置并删除它,但下次登录时,我会再次收到提示以保存此站点的密码。当出现提示时,我无法阻止此站点上的其他用户保存他们的密码。

我知道有很多类似的问题,但似乎没有一个对我有用。我已经尝试过(除其他外):

  1. 在我的 TextBox 中设置 autocomplete="off" 属性
  2. 在我的 TextBox 中设置 AutoCompleteType="Disabled" 属性
  3. 这个:https://stackoverflow.com/a/36904814/4241820

我的银行网站能够防止密码被保存或预填。这是怎么做到的?

更新:这是来自我的 Login.aspx 页面的代码:

<%@ Page Title="" Language="C#" MasterPageFile="./MyMasterPage.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="MyApp.Login" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table style="width: 294px; margin-left: auto; margin-right: auto; margin-top: 80px; margin-bottom: auto; border: none; border-collapse: collapse;">
        <tr style="background-color: #FFFFFF;">
            <td style="text-align: center;">
                <br />
                <img src="Images/AppLogo.png" alt="Application Logo" />
            </td>
        </tr>
        <tr>
            <td style="background-color: #FFFFFF; text-align: center;">
                <asp:PlaceHolder runat="server" ID="LoginStatus" Visible="false">
                    <p>
                        <asp:Label ID="lblStatus" CssClass="lblSkin" runat="server" />
                    </p>
                </asp:PlaceHolder>
                <asp:PlaceHolder runat="server" ID="LoginForm" Visible="false">
                    <br />
                    <asp:Label ID="lblTitle" CssClass="lblSkinLarge" runat="server" /><br />
                    <br />
                    <div style="margin-bottom: 10px">
                        <input style="display: none" type="text" name="fakeusername" />
                        <asp:Label Text="Username" CssClass="lblSkin" AssociatedControlID="UserName" runat="server" /><br />
                        <asp:TextBox runat="server" ID="UserName" Width="244px" autocomplete="off" AutoCompleteType="Disabled" />
                    </div>
                    <div style="margin-bottom: 10px">
                        <input style="display: none" type="password" name="fakepassword" />
                        <asp:Label Text="Password" AssociatedControlID="Password" CssClass="lblSkin" runat="server" /><br />
                        <asp:TextBox runat="server" ID="Password" TextMode="Password" Width="244px" autocomplete="off" />
                    </div>
                    <div style="margin-bottom: 10px">
                        <div>
                            <asp:ImageButton AlternateText="Login" ImageUrl="~/Images/btnLogin.jpg" OnClick="SignIn" runat="server" />
                            <br />
                            <asp:HyperLink ID="lnkForgotPassword" CssClass="lblSkin" NavigateUrl="Login_ResetPassword.aspx" Text="Forgot password" runat="server" />
                        </div>
                    </div>
                </asp:PlaceHolder>
                <asp:PlaceHolder runat="server" ID="LogoutButton" Visible="false">
                    <div>
                        <div>
                            <asp:Button runat="server" OnClick="SignOut" Text="Log out" />
                        </div>
                    </div>
                </asp:PlaceHolder>
            </td>
        </tr>
    </table>
</asp:Content>

【问题讨论】:

    标签: c# asp.net google-chrome


    【解决方案1】:

    不要在文本框上设置autocomplete="off",而是在放置它的表单上。

    &lt;form id="form1" runat="server" autocomplete="off"&gt;

    【讨论】:

    • 感谢您的回复。我在母版页(包含文本框)的“表单”中添加了 autocomplete="off"。但是当我加载页面时,仍然会出现预先填写的用户名。
    • @Windhoek 我不知道为什么它仍然出现,但有一个建议,不要使用相同的母版页登录和其他页面。如果您在母版页中将身份验证相关的东西作为一个常见的跨应用程序来做,那就太麻烦了。
    • 这并不能解决问题。他想关闭一个字段而不是整个表单的自动完成功能。
    【解决方案2】:

    我们遇到了同样的情况,但我遵循以下方法来克服这种情况

    在您的 txtInsuredPassword 之前的标记内的新页面中,尝试保留此输入类型,以便您的问题得到解决

       <input style="display: none" type="text" name="fakeusername" />
      <input style="display: none" type="password" name="fakepassword" />
    

    尽量将此marup保持在您的实际用户名和密码之上

    【讨论】:

    • 感谢您的建议。我试过了,但预填的用户名和密码仍然出现。
    • @Windhoek 你能分享一下你是如何添加的代码吗?
    • 这里是:'

      '
    • @Windhoek 请在问题中发布完整页面代码
    • 我按要求在问题中发布了代码。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多