views:

409

answers:

1

I want to build portal-like asp.net web application from scratch and was looking at asp.net MembershipProvider as a standard way for user's management. I created my provider inheriting from SqlMembershipProvider and override ValidateUser method:

        public override bool ValidateUser(string username, string password)
        {
            string temp = ApplicationName;
            List<MtscApp> allApps = GetAllApplications();
            foreach (MtscApp app in allApps)
            {
                ApplicationName = app.Name;
                Roles.ApplicationName = app.Name;
                if (base.ValidateUser(username, password))
                {
                    return true;
                }
            }
            ApplicationName = temp;
            Roles.ApplicationName = temp;
            return false;
        }

I'm trying to validate entered credentials against all applications, while GetAllApplicationsMethod() gets all applications from aspnet_Applications table (I also have part for inserting applications in the same table).

If validation succeed then Application name is leaved on both Membership and Roles providers, otherwise it stays on the default one which is predefined application for anonymous users.

+1  A: 

Yes, I've done somethihng similar on several occasions. The only difference being that I look the application name up in a database table based on the URL the user comes in off of and only validate for that one app. The table has two fields, URL and ApplicationName. The ApplicationName is the same ApplicationName as the aspnet_Applications.ApplicationName field.

Robert C. Barth