Is it possible to change the username with the Membership API

It’s true that the default SQL Membership Provider does not allow username changes. However, there’s no intrinsic reason to prevent users from changing their usernames if you have a valid argument, on your site, to allow it. None of the tables in the SQL database have the username as a key, everything is based on … Read more

Dependency injection and ASP.Net Membership Providers

If you are configuring the custom membership providers via the <membership> element in the Web.config file, then I can see the issues you will have with dependency injection. The providers are constructed and managed by the framework, and there is no opportunity for you to intercept that construction to provide additional dependency injection for the … Read more

Custom MembershipProvider in .NET 4.0

It’s very simple really: Create a new Class file (if you’re not using a multi-layered system, in your project’s Models folder) let’s called MyMembershipProvider.cs Inherit that class from System.Web.Security.MembershipProvider automatically create the needed methods (period + space in the inherit class) Done! All methods will have the NotImplementedException exception, all you need to do is … Read more

SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified [closed]

If you are connecting from Windows machine A to Windows machine B (server with SQL Server installed), and are getting this error, you need to do the following: On machine B: 1.) turn on the Windows service called “SQL Server Browser” and start the service 2.) in the Windows firewall, enable incoming port UDP 1434 … Read more

How do you change a hashed password using asp.net membership provider if you don’t know the current password?

This is an easy one that I wasted too much time on. Hopefully this post saves someone else the pain of slapping their forehead as hard as I did. Solution, reset the password randomly and pass that into the change method. MembershipUser u = Membership.GetUser(); u.ChangePassword(u.ResetPassword(), “myAwesomePassword”);

How do I create a custom membership provider for ASP.NET MVC 2?

I have created a new project containing a custom membership provider and overrode the ValidateUser method from the MembershipProvider abstract class: public class MyMembershipProvider : MembershipProvider { public override bool ValidateUser(string username, string password) { // this is where you should validate your user credentials against your database. // I’ve made an extra class so … Read more

How do I use my own database with SimpleMembership and WebSecurity? What is MVC4 security all about?

See the summaries below each quote for a quick answer, and the paragraphs for detail. Also see the References section at the end for the authoritative sources. Summaries 1.What is SimpleMembership/SimpleMembershipProvider (WebMatrix.WebData) and what is it/are they responsible for? SimpleMembership (a term that covers both the SimpleMembershipProvider and SimpleRoleProvider) is responsible for providing a clean … Read more

Anti forgery token is meant for user “” but the current user is “username”

This is happening because the anti-forgery token embeds the username of the user as part of the encrypted token for better validation. When you first call the @Html.AntiForgeryToken() the user is not logged in so the token will have an empty string for the username, after the user logs in, if you do not replace … Read more