HttpContext.Current.User.Identity.Name is always string.Empty

FormsAuthentication.SetAuthCookie(tbUsername.Text, true); bool x = User.Identity.IsAuthenticated; //true string y = User.Identity.Name; //”” The problem you have is at this point you’re only setting the authentication cookie, the IPrincipal that gets created inside the forms authentication module will not happen until there is a new request – so at that point the HttpContext.User is in a … Read more

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