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.