YAFLogo

CodeJunky2008
16 years ago
So this one was bugging the hell out of me excuse the pun. In the end I had to write an HttpHandler to look into the application cache and see what was going on.

Now this works for me but I haven't had the code live long enough to be 100% sure but worth a try. It's only few lines of code.

I also under Jaben's advice decided to create the forums under it's own app pool in IIS and make the YetAnotherForum.Net website into a C# web application. If you need advice on this PM me.

YAFProviders.YAFRoleProvider.cs has an override method GetRolesForUser() which puts the currents users role memberships into cache under a cache entry called 'YafRoleProvider-UserRoleDictionary-YetAnotherForum'. This code only runs if the user's Session["UserUpdated"] == null i.e. user has just logged in or no activity for say 20 mins (server specific) and IIS has dropped the session.

I'm not sure why but when 'YafRoleProvider-UserRoleDictionary-YetAnotherForum' is dropped out of cache it doesn't always get recreated. So this is how I fixed the issue.

This code belongs inside InitUserAndPage() method,

1.9.3 alpha (YAF.Base.ForumPage.cs)

1.9.3 beta to RC2 (YAF.Classes.Utils.Context.cs)

Original code


            if (user != null && Session["UserUpdated"] == null)
            {
                RoleMembershipHelper.UpdateForumUser(user, PageContext.PageBoardID);
                Session["UserUpdated"] = true;
            }
       

Amended code

if (user != null && Session["UserUpdated"] == null)
            {
                RoleMembershipHelper.UpdateForumUser(user, PageContext.PageBoardID);
                Session["UserUpdated"] = true;
            }
            else if (user != null)
            {
              string[] roles =  System.Web.Security.Roles.GetRolesForUser(user.UserName);
            }

There shouldn't be any real additional overhead for performance because the method simply checks the cache to see if it exists. If no entry it recreates it and returns the roles as a string array.

I will let Jaben and other more experienced developers discuss why. It's just a quick and simple fix (for me) I hope it might help some of you guys. But it makes sense that if the roles are not present and were before access would be an issue. Hopefully it's as simple as this but maybe not!

CJ

P.S.

This is the code to create the HttpHandler, create the class in its own class library and then add a reference to the website or web application (YetAnotherForum.Net)


using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Collections;
using System.IO;


namespace CachingManagerTool
{
    public class CacheManager : IHttpHandler
    {

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            string output = string.Empty;
            IDictionaryEnumerator enumerator = context.Cache.GetEnumerator();
            while (enumerator.MoveNext())
            {
                output += context.Cache[enumerator.Key as string];
                Type t = enumerator.Value.GetType();//You could write out the cache I just wanted a point to debug and watch the value and key.
            }
        
        }

        #endregion
    }
}

Put this in the web.config

To look at the cache set a break point in the CacheManager.cs and then in the brower url replace default.aspx with cache.axd and hit return. If you are in debug mode you should hit the break point and be able to look in your cache. Good luck

Sponsor
Jaben
  • Jaben
  • 100% (Exalted)
  • YAF Developer
16 years ago
Wow, thanks for all this CodeJunky!

I hope this fixes it for you. I kind of had an idea that it was related to cache issues. Low memory/cache issues are a terrible, terrible thing to try to debug.

Please keep us updated....

CodeJunky2008
16 years ago
Thanks, I can report that the problem is fixed and I have asked moderators to test and they are reporting everything as working perfectly. This is the first time I have ever gone over 2 hours without incident and the new code has been live for over 4 hours.

If anything changes I will let you know

CJ

CodeJunky2008
16 years ago
😞 The problem came back but it took a lot longer to happen than normal. Originally it would occur in the first few hours this time it took over 10 hours. I am going to have to write some reporting tools to find out what the hells happening. Gutted I thought I had put this one to bed.

The nightmare continues:x

Jaben
  • Jaben
  • 100% (Exalted)
  • YAF Developer
16 years ago
Sorry to hear that. How long is your application refresh time in IIS? Maybe set it to something like 8 hours?
CodeJunky2008
16 years ago
When you say IIS refresh time, I only know of recyling the pool. Is this a setting under an options tab. Has nobody else reported this problem to you?
Jaben
  • Jaben
  • 100% (Exalted)
  • YAF Developer
16 years ago
Sorry, I meant application pool recycle time. No, I haven't heard of anyone else having this issue. But your forum may be larger than most. I run YAF on my server and haven't had a lot of issues. But I do notice it IIS gets a little weird after a while occasionally (we're talking a week or two).