0

I am running a blog on Community Server 2008 SP2 (this is a blog software from between 2008-2011), with ASP.NET 2.0. Comments are currently not working, and I'm looking into why it's not working.

When I looked into the exception logs, I see:

Exception Type: RoleNotFound

User Agent:
Path: as HTTP
Referrer:
Message: Error while trying to find a role for the user 'chuacw'. Possible cause is a invalid client cookie or a user rename.
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.Security.Roles.GetRolesForUser(String username)
at CommunityServer.ASPNet20MemberRole.CSRoles.GetRolesForUser(String userName)
at CommunityServer.Components.Roles.UserRoleIDsCollection.LoadFromDatabase(String username)

To investigate this, I created testrole.aspx, with the following contents:

<%@ Page %>
<%@ Register TagPrefix="CSM" Namespace="CommunityServer.ASPNet20MemberRole" 

Assembly= "CommunityServer.ASPNet20MemberRole" %>
<%@ Register TagPrefix="Custom2" Namespace="CommunityServer.Components" 

Assembly= "CommunityServer.Components" %>

<% 
      String username = "chuacw";
      CommunityServer.ASPNet20MemberRole.CSRoles role = new 

CommunityServer.ASPNet20MemberRole.CSRoles();

      CommunityServer.Components.Role[] lRoles = role.GetRoles();
      foreach (CommunityServer.Components.Role lRole in lRoles) {
        Response.Write("Role: " + lRole.Name + "<br />");
      }
      Response.Write("<br/>");

      Response.Write("Username is: " + username + "<br />");

      String[] roles = role.GetRolesForUser(username);
      foreach (string lSrole in roles) {
         Response.Write(lSrole + "<br/>");  
      }
%>

And I opened up this page directly in a browser, from my site, ie, http://mysite/testrole.aspx without logging in to my site.

This code worked and I was able to see a list of roles, and the username.

Given that my code called CommunityServer.ASPNet20MemberRole.CSRoles.GetRolesForUser, which is the same method called by the code that raised the exception earlier in the beginning of this question, I'm unable to comprehend why this exception is thrown.

I am the administrator of this database, and I am the user "chuacw". I can log into this blog software using this user.

Does anyone have any ideas how I can further investigate this? I do not have the source to this, however, I can use ILSpy and Reflector, and write new code to test this.

My hope is to find the underlying conditions leading to this error, and fix the cause.

Thank you.

chuacw
  • 1,100
  • 1
  • 19
  • 34
  • The error is pretty clear - there's no such user in the database. There's **no** reason to write code in an ASPX page just to test how an ASP.NET method behaves, or whether a user exists. Just write a Unit Test and call the methods. – Panagiotis Kanavos Jul 21 '20 at 08:48
  • Hi Panagiotis, no, that's not the case. I am the administrator of this database, and I can log into the system using this particular user. – chuacw Jul 21 '20 at 08:49
  • Community Server used ASP.NET's authentication and membership mechanisms, so you can just check the database to see whether the users or roles are there, and even use ASP.NET Membership classes to retrieve user profiles etc. – Panagiotis Kanavos Jul 21 '20 at 08:50
  • Yeah, that's exactly what I've done. The user and the roles are there, I opened up SQL Management Studio to check. It's Community Server that's throwing up the weird issues. – chuacw Jul 21 '20 at 08:52
  • `I am the administrator of this database, and I can log into the system` in that case you wouldn't have any problems. CS may be old, but never had such issues. I have a CS site that works without stop since 2008. The problems have to do with HTML and CSS changes, editors that no longer work with newer browsers but *never* with ASP.NET's built-in providers. If you have an error, something was modified – Panagiotis Kanavos Jul 21 '20 at 08:53
  • What did you change? Something that worked for 12 years didn't just decide to stop working. And if CS is really at fault, you can just use ASP.NET's membership classes directly, to load users and their profiles. If you can't do even that, the problem is with the entire system - a changed database? Connection string? Modified permissions? – Panagiotis Kanavos Jul 21 '20 at 08:53
  • Did you migrate to a new SQL Server version perhaps? Have you tried lowering the compatibility level in that case? CS 2008 used features (especially query HINTs) that may be deprecated or whose behaviour has changed. – Panagiotis Kanavos Jul 21 '20 at 08:57
  • No, I didn't upgrade the SQL Server at all. Now I'm suspecting that I might have changed a column's type, unfortunately, I don't remember when I did this, so I'm going to try and restore a backup from 2 weeks ago and see if that works. – chuacw Jul 21 '20 at 08:59
  • CS used some rather ... questionable techniques to achieve high throughput and low blocking with SQL Server 2005, including `NOLOCK` hints spread all over the place. Modifying the database should be done with care. – Panagiotis Kanavos Jul 21 '20 at 09:08
  • Panagiostis, can we go into a chat for me to tap your brain? If I accidentally changed the schema, how can I restore it back? My earlier restore of the database back to 2 weeks ago didn't solve the issue, because I saw the same error for another user dating back to 2 years ago, and I didn't make any changes back then. – chuacw Jul 21 '20 at 09:13

0 Answers0