CodeJunky2008
2008-11-25T21:58:22Z
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
<httpHandlers>

<add verb="*" path="cache.axd" type="CachingManagerTool.CacheManager, CachingManagerTool"/>
</httpHandlers>

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
2008-11-25T23:31:05Z
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
2008-11-26T01:02:04Z
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
2008-11-26T21:49:33Z
😞 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
2008-12-02T14:21:20Z
Sorry to hear that. How long is your application refresh time in IIS? Maybe set it to something like 8 hours?
CodeJunky2008
2008-12-02T22:30:33Z
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
2008-12-02T23:01:50Z
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).

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved