Remove browser autocompletion in MVC

2019-04-06 23:48发布

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.

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".

4条回答
smile是对你的礼貌
2楼-- · 2019-04-07 00:13

If you check HERE, setting autocomplete="off" on the form should do the trick.

查看更多
贪生不怕死
3楼-- · 2019-04-07 00:20

You can randomize id and name attributes of your textboxes - this will make browser autocomplete functions not working.

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];
...
查看更多
Viruses.
4楼-- · 2019-04-07 00:29

There is an autocomplete=off property in html.

It is used in the top right search box on this very page, inspect the html you'll see:

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

See this MDN article: 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:

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

OR

Html.TextBoxFor(model => model.EmployerNumber, new {autocomplete="off"})
查看更多
看我几分像从前
5楼-- · 2019-04-07 00:34

The HTML5 have a add-on syntax for form/input elements, it is called autocomplete="off". See http://www.w3schools.com/html5/att_form_autocomplete.asp

查看更多
登录 后发表回答