How to prevent Google Chrome from saving passwords in ASP.NET MVC?
Is there a way to prevent Google Chrome and other browsers from saving a password for a spec开发者_JAVA技巧ific site? The server is ASP.NET MVC .NET4.
Try autocomplete='off'
on the input field. Browsers should respect this - but of course they don't have to.
UPDATE:
This is now part of HTML5, and according to that standard you can add autocomplete='off'
to the form tag to have it apply to all fields within the form.
http://www.w3schools.com/html/html5_form_attributes.asp
I guess you are asking about programmatic way of preventing the save password dialog and not by using the configurable options available at the browser (if you are looking for configurable options this link may help Google Chrome Manage Password).
Now coming to programmatic way, there are many ways to do it. Lets say you have a password field with name pass:
<input type="password" name="pass">
You have to add couple of additional dummy password field on top of the original password field (which in our case name="pass").
Those additional dummy password field should not be visible to users so we have to control the display aspect of those dummy password field using style sheet display: none
Eg:
<input type="password" name="password_fake" id="password_fake" value="" style="display:none;" />
Note this sometimes may not work, in that case try to use other css styles to hide the elements from the users.
Hide elements via CSS
Let me know if it helps.
When the user clicks "submit", take the password from the form field, put it in a hidden input and send the form.
For chrome - and other browsers that don't respect autocomplete="off"
- you can use autoCompleteType="disable"
or x-autoCompleteType="disable"
精彩评论