简体   繁体   English

删除MVC中的浏览器自动完成功能

[英]Remove browser autocompletion in MVC

I am currently trying to remove the form autocompletion done by the user's browser which can cause some critical behavior since it fills the password field. 我目前正在尝试删除用户浏览器完成的表单自动完成,这可能会导致一些关键行为,因为它填写了密码字段。 I have already added the autocompletion attribute to all of my textbox fields but when I try with firefox it stills load my current login information into the fields. 我已经在我的所有文本框字段中添加了autocompletion属性,但是当我尝试使用firefox时,它仍会将我当前的登录信息加载到字段中。

Does anyone know how to resolve this issue? 有谁知道如何解决这个问题?

EDIT: Since it's not clear, I have already added the aucompletion attribute with the value set to "off". 编辑:由于不清楚,我已经添加了aucompletion属性,其值设置为“off”。

There is an autocomplete=off property in html. html中有一个autocomplete=off属性。

It is used in the top right search box on this very page, inspect the html you'll see: 它在此页面的右上角搜索框中使用,检查您将看到的html:

<input autocomplete=​"off" name=​"q" class=​"textbox" placeholder=​"search" ..... />

See this MDN article: https://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion 请参阅此MDN文章: https//developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion

In MVC you would implement this at the form or for a textbox like so: 在MVC中,您可以在表单或文本框中实现它,如下所示:

Html.BeginForm(
    action, controller, FormMethod.Post, new {autocomplete="off"})

OR 要么

Html.TextBoxFor(model => model.EmployerNumber, new {autocomplete="off"})

如果你在这里检查,在表单上设置autocomplete="off"就可以了。

You can randomize id and name attributes of your textboxes - this will make browser autocomplete functions not working. 您可以随机化文本框的id和name属性 - 这将使浏览器自动完成功能无法正常工作。

My implementation 我的实施

In view: 在视图中:

<%
    var guidString = Guid.NewGuid().ToString();
%>
<%=Html.TextBox(guidString, String.Empty)%>
<%=Html.Hidden("NameGuid", guidString) %>

in Controller: 在控制器中:

string userName = Request[model.NameGuid];
...

The HTML5 have a add-on syntax for form/input elements, it is called autocomplete="off". HTML5具有表单/输入元素的附加语法,称为autocomplete =“off”。 See http://www.w3schools.com/html5/att_form_autocomplete.asp 请参阅http://www.w3schools.com/html5/att_form_autocomplete.asp

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM