All users deleted in users.xml

Jul 7, 2010 at 10:33 AM
Edited Jul 7, 2010 at 10:35 AM
Hi I have encountered a strange case. I am using the xml membership, role and profile providers in a asp.net webservice. The webservice has roughly 100 users configured. Approximate message rate is 5 per second. For each message, the webservice invokes Roles.IsUserInRole and Membership.GetUser

It has happened twice that the all the users defined in the users.xml are completely deleted. Contents of users.xml after corruption
<?xml version="1.0"?> <ArrayOfXmlUser xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:nil="true" />
User config in Web.config
<!-- ############################################################################### --> <!-- ## Security Providers Membership and Roles --> <!-- ############################################################################### --> <membership defaultProvider="XmlMembershipProvider"> <providers> <clear /> <!-- PasswordFormat: Clear, Hashed, Encrypted --> <add applicationName="my App" name="XmlMembershipProvider" type="Artem.Web.Security.XmlMembershipProvider" minRequiredPasswordLength="0" minRequiredNonAlphanumericCharacters="0" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Clear" /> </providers> </membership> <roleManager enabled="true" defaultProvider="XmlRoleProvider"> <providers> <clear /> <add applicationName=" my App " name="XmlRoleProvider" type="Artem.Web.Security.XmlRoleProvider" /> </providers> </roleManager> <profile enabled="true" defaultProvider="XmlProfileProvider"> <providers> <clear /> <add applicationName=" my App " name="XmlProfileProvider" type="Artem.Web.Security.XmlProfileProvider" /> </providers> <!-- Here are the properties of the profile --> <properties> <add name="P1" type="string" /> <!—p1--> <add name="P2" type="bool" /> <!—p2--> </properties> </profile>

Has anyone encountered such problems ? Any other ideas ?
Jul 14, 2010 at 8:15 PM

I've run into this as well, but I still haven't figured it out. I actually had the same thing happen to my Roles and Profile XML files in addition to my User file. I ran into it most recently with my Profile file, especially on my local machine programming in Visual Studio whenever I switched between "Start without Debugging" and "Start Debugging". I found out that the membership framework in ASP.NET re-saves the profile and user files A LOT in order either update the "last activity" of a user, or if for any other reason it thinks the data may need to be flushed and updated (which it doesn't most of the time). I suspected that in the implementation of these XML providers, the constant flushing to the file eventually causes something to go wrong. It's also possible I ran into this when switching between non-debug and debug because it lost it's cache during the flushing process. I don't know, but it sucks.

My website went live using these providers as of 2 days ago, and I still never found the problem. In order to protect the data, I had my site backup my user, roles, and profile files every time the login page was loaded. It would check the files, and specifically if my user name, role, or profile were missing or incorrect, it would copy the backups over the real files, otherwise make new backups. Here's the code for the function I call from my login.aspx.cs in the Page_Load function:

   private void BackupMembershipInfo()
   {
      string l_username = "myusername"; // TODO: Set this to some user's name you know should always have a user account, populated profile, and role
      MembershipUser u = Membership.GetUser(l_username);
      ProfileCommon p = Profile.GetProfile(l_username);
      string[] r = Roles.GetRolesForUser(l_username);

      string l_Path = Server.MapPath("~/App_Data/");
      string l_BackupPath = Server.MapPath("~/App_Data/backup/");
      string l_UsersFile = "Users.xml";
      string l_ProfileFile = "Profile.xml";
      string l_RolesFile = "Roles.xml";

      if (u != null && (!String.IsNullOrEmpty(p.FirstName)) && r.Length != 0) // It's good, so back it up
      {
         if (!Directory.Exists(l_BackupPath))
         {
            Directory.CreateDirectory(l_BackupPath);
         }
         File.Copy(
            String.Concat(l_Path, l_UsersFile),
            String.Concat(l_BackupPath, l_UsersFile),
            true // overwrite
            );
         File.Copy(
            String.Concat(l_Path, l_ProfileFile),
            String.Concat(l_BackupPath, l_ProfileFile),
            true // overwrite
            );
         File.Copy(
            String.Concat(l_Path, l_RolesFile),
            String.Concat(l_BackupPath, l_RolesFile),
            true // overwrite
            );
      }
      else // Lost something, bring it all back
      {
         if (Directory.Exists(l_BackupPath))
         {
            File.Copy(
               String.Concat(l_BackupPath, l_UsersFile),
               String.Concat(l_Path, l_UsersFile),
               true // overwrite
               );
            File.Copy(
               String.Concat(l_BackupPath, l_ProfileFile),
               String.Concat(l_Path, l_ProfileFile),
               true // overwrite
               );
            File.Copy(
               String.Concat(l_BackupPath, l_RolesFile),
               String.Concat(l_Path, l_RolesFile),
               true // overwrite
               );
         } // if backups exist
      } // Else we lost files
   } // end backup function

 

It's not ideal, but this provider has been the best XML provider I've seen on the net. I hope this helps. If you have any other problems, see my other discussion posts and issues submitted, or feel free to ask. I've tried my best to document my problems and work arounds when using this, that way others don't have to deal with the frustration of finding an XML provider that works.

Developer
Apr 22, 2011 at 3:42 AM

I will be joining this project soon as I have modified the .net 4 version of this project to fix this issue. It is a multi-threading issue. You can see the discussion http://tinyproviders.codeplex.com/discussions/254213

Developer
Apr 29, 2011 at 12:19 AM

I will be working on this as soon as I can get VS 2008 installed. I expect that to be this Saturday after I fix the .net 4.0 Version.