Forum access denied.

Topics: Project Management Forum, User Forum
Nov 19, 2008 at 5:16 PM
Edited Nov 19, 2008 at 5:17 PM
Hi all, i'm using this great webpart on my intranet but i've problem accessing forum.
Only Web Application Owner can view the page with forum webpart, all other users no.

Why ?

Thanks in advance.
Best Regards

Antonio Sessa

Mar 4, 2009 at 4:55 PM
I'm facing the some problem.
If you solved that could you tell me?
thank you,

Regards,
Pablo Bertrão
Mar 10, 2009 at 5:50 PM
Edited Mar 10, 2009 at 6:40 PM
asessa, I solved the problem.

Try to create a new permission level called "List permissions"
In this permission, select "manage lists" and then create.
Give the user or group this permission and you shold see your wbpart working well.
Thanks to Tequila00shots

Regards,
Pablo Bertrão
Mar 14, 2009 at 1:43 AM
I ended up making a code change to fix this issue. 

The issue is with the function InitializeApplication.  It uses the current's context SPWeb object for all of the list updates.  Since this object is created outside of the impersonation, the object has the permissions of the logged in user instead of the impersonated admin account.  I made the following code change that fixed it for me:

private void InitializeApplication()
  {
   UrlQuery query = new UrlQuery(this.Page.Request.Url.ToString());
            using (SPSite site = new SPSite(SPControl.GetContextWeb(Context).Url))
            {
                SPWeb web = site.OpenWeb();
       ForumApplication.Instance.BasePath = SPEncode.UrlEncodeAsUrl(query.Url);
       ForumApplication.Instance.Title = this.Name;
       ForumApplication.Instance.ForumCache = this.Page.Cache;
       ForumApplication.Instance.ClassResourcePath = this.ClassResourcePath;
                ForumApplication.Instance.SpUser = SPControl.GetContextWeb(Context).CurrentUser;
                ForumApplication.Instance.AppPoolUser = web.CurrentUser;
                ForumApplication.Instance.SpWeb = web;
            }
  }

And since this object needs to be disposed, I added this code to the bottom of the RenderWebPart function:

if (ForumApplication.Instance.SpWeb != null)
            {
                ForumApplication.Instance.SpWeb.Dispose();
            }

There probably is a better place for this, like onunload but I just needed a quick bandaid until the official next version comes out.
Mar 16, 2009 at 7:39 PM
Edited Mar 16, 2009 at 7:53 PM
So I would like to make this code change but I can't find the BilSimser.SharePoint.Common.dll anywhere. Anyone know how I can get it?
Mar 16, 2009 at 8:43 PM
Install MSI
Then extract the following cab

Found it finally..... C:\Program Files\WPPackager\{14aa60ab-2b6b-4254-b45e-0ef7b8b2a201}\SharePointForums-1.2.0.0_Bil Simser.cab
Mar 24, 2009 at 6:15 PM
Edited Mar 25, 2009 at 4:35 PM
Thank you, shocksll and sikemullivan.

But I'm having some problems trying to compil the source.
If it's possible, could you send to me or available the fixed DLL?
I will keep trying to fix, because the source is giving to me a lot of erros.
I don't know if is because I'am using Visual Studio 2008.
I will keep checking.


Really thanks for this help.

Regards.
Pablo Bertrão
Jun 4, 2009 at 6:43 AM

Dear shocksll,

Could you tell me where the code should be put in?   what are the file names?

Thanks a lot.

 

Dear legendsofthekid,

Could you tell me how to create "manage list" option?

Thanks a lot.

Jun 4, 2009 at 11:43 AM

It's in SharePointForumWebPart.cs

Jun 5, 2009 at 7:41 AM
Edited Jun 5, 2009 at 7:43 AM

Dear shocksll,

Thanks for your response.  I added your code into SharePointForumWebPart.cs just like the following.

 But I still cannot let our common users (usually the users are just the site vistors which I setup the permission to them in advance), Unless I setup the permission as full-controll. 

What can I do for the next step? Could you kindly help me?   Whether or not I should re-install the whole forums again following the instruction from step 1 to 4?

Thanks.

__________________________________________________

#region Using Directives

using System;
using System.ComponentModel;
using System.Threading;
using System.Web.UI;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Collections;
using System.Text;
using BilSimser.SharePoint.Common.Service;
using BilSimser.SharePoint.WebParts.Forums.Controls;
using BilSimser.SharePoint.WebParts.Forums.Controls.Base;
using BilSimser.SharePoint.WebParts.Forums.Core.Service.Application;
using BilSimser.SharePoint.WebParts.Forums.Core.Service.Builders;
using BilSimser.SharePoint.WebParts.Forums.Utility;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

#endregion

namespace BilSimser.SharePoint.WebParts.Forums
{
 [ToolboxData("<{0}:SharePointForumWebPart runat=server></{0}:SharePointForumWebPart>")]
 [XmlRoot(Namespace="BilSimser.SharePoint.WebParts.Forums")]
 public class SharePointForumWebPart : WebPart
 {
  #region Fields

  private const string STR_RESOURCE_STRING = "/strings/string[@id='{0}']";
  private const string STR_LANGUAGE_FILTER = "*.lng.xml";
  private const string STR_DEFAULT_LANGUAGE = "1033";
  private const string STR_DEFAULT_DATE_FORMAT = "F";
  private const string STR_DEFAULT_FORUM_NAME = "Discussion Forums";

  private string _name = STR_DEFAULT_FORUM_NAME;
  private int _postCount = 0;
  private int _topicCount = 0;
  private int _forumCount = 0;
        private string _currentLanguage = STR_DEFAULT_LANGUAGE;
  private string _dateFormat = "F";
  private XmlDocument _resourceFile;
  private ArrayList _errorList = new ArrayList();

  #endregion

  #region Properties

  public ArrayList ErrorList
  {
   get { return _errorList; }
  }

  [Description("Format for date dislays in your discussion forum."), DefaultValue("F"), WebPartStorage(Storage.Shared), FriendlyName("Date Format"), Category("Forum Properties"), Browsable(false)]
  public string DateFormat
  {
   get
   {
    return this._dateFormat;
   }
   set
   {
    this._dateFormat = value;
   }
  }

  public bool IsValid
  {
   get { return ErrorList.Count == 0; }
  }

  [Category("Forum Properties")]
  [DefaultValue(STR_DEFAULT_FORUM_NAME)]
  [WebPartStorage(Storage.Shared)]
  [FriendlyNameAttribute("Forum Name")]
  [Description("Display name for your discussion forum.")]
  [Browsable(false)]
  public string Name
  {
   get { return _name; }
   set { _name = value; }
  }

  [Category("Forum Properties")]
  [DefaultValue(0)]
  [WebPartStorage(Storage.Shared)]
  [FriendlyNameAttribute("Post Count")]
  [Description("Number of posts in this forum.")]
  [Browsable(false)]
  public int PostCount
  {
   get { return _postCount; }
   set { _postCount = value; }
  }

  [Category("Forum Properties")]
  [DefaultValue(0)]
  [WebPartStorage(Storage.Shared)]
  [FriendlyNameAttribute("Forum Count")]
  [Description("Number of forums in this site.")]
  [Browsable(false)]

  public int ForumCount
  {
   get { return _forumCount; }
   set { _forumCount = value; }
  }

  [Category("Forum Properties")]
  [DefaultValue(0)]
  [WebPartStorage(Storage.Shared)]
  [FriendlyNameAttribute("Topic Count")]
  [Description("Number of topics in this forum.")]
  [Browsable(false)]
  public int TopicCount
  {
   get { return _topicCount; }
   set { _topicCount = value; }
  }

  #endregion

  #region Protected Methods

  protected override void OnInit(EventArgs e)
  {
   using (Identity.ImpersonateAppPool())
   {
    LoadResourceFileStrings();
    InitializeApplication();
    CheckAndBuildLists();
   }
  }

  protected override void OnLoad(EventArgs e)
  {
   /*
    * BUG: update isn't working
    *
   using (Identity.ImpersonateAppPool())
   {
    UpdateCurrentUserVisitTime();
   }
   */
  }

  protected override void RenderWebPart(HtmlTextWriter output)
  {
   if (output == null)
    return;

   try
   {
    EnsureChildControls();
    
    if(IsValid)
    {
     using (Identity.ImpersonateAppPool())
     {
      foreach (Control control in this.Controls)
      {
       control.RenderControl(output);
      }
     }
    }
    else
    {
     RenderError(output);
    }
   }
   catch (ThreadAbortException)
   {
    // this is thrown when the RSS feed completes so ignore it  
    // TODO: find a better way to render RSS so we don't throw the exception
   }
   catch (Exception unhandledException)
   {
    RenderError(output, unhandledException);
   }
  }

  /// <summary>
  /// Notifies server controls that use composition-based implementation to create any child
  /// controls they contain in preparation for posting back or rendering.
  /// This will read in a QueryString called "control" and instantiate a server
  /// control with the same name then add that to the Web Parts controls.
  ///
  /// If no QueryString called "control" is found or invalid, we fall back to the
  /// basic <see cref="ViewForums"/> which just displays the default forum(s).
  /// </summary>
  protected override void CreateChildControls()
  {
   using (Identity.ImpersonateAppPool())
   {
    SharePointForumControls childControl;

    try
    {
     childControl = (SharePointForumControls) Enum.Parse(typeof (SharePointForumControls), Page.Request.QueryString["control"], true);
    }
    catch
    {
     childControl = SharePointForumControls.ViewForums;
    }

    BaseForumControl control = CreateDynamicForumControl(childControl);
    if(control != null)
     Controls.Add(control);
   }
  }

  private BaseForumControl CreateDynamicForumControl(SharePointForumControls childControl)
  {
   BaseForumControl control = null;
   
   try
   {
    string controlTypeName = string.Format("{0}.{1}", ForumConstants.Control_Namespace, childControl.ToString());
    Type controlType = Type.GetType(controlTypeName);
    control = Activator.CreateInstance(controlType) as BaseForumControl;
    control.WebPartParent = this;
   }
   catch(ArgumentNullException nullEx)
   {
    AddError(nullEx);
   }

   return control;
  }

  #endregion

  #region Private Methods

  public void RenderError(HtmlTextWriter output, Exception ex)
  {
   AddError(ex);
   RenderError(output);
  }

  private void RenderError(HtmlTextWriter output)
  {
   StringBuilder sb = new StringBuilder();
   foreach(Exception ex in ErrorList)
   {
    sb.AppendFormat("{0}<br>", ex.Message);
   }

   output.WriteLine("An error has occurred with the Forums Web Part.");
   output.WriteLine("See the details below for more information.</p>");
   output.WriteLine("<div class=\"ms-alerttext\">{0}</div>", sb.ToString());

   // TODO: get more system information to email
   output.WriteLine("</p><strong><a href=\"mailto:{0}?Subject=Forum Error&Body={1}\">Email error information to support</a></strong></p>", ForumConstants.Config_Author_Email, sb.ToString());
   output.WriteLine("<a href=\"{1}\">Return to {0} Home</a>", this.Name, ForumApplication.Instance.GetLink(SharePointForumControls.ViewForums));
  }

  private void LoadResourceFileStrings()
  {
   try
   {
    string resources = GetResourceDirectory();
    DirectoryInfo directoryInfo = new DirectoryInfo(this.Page.Server.MapPath(resources));
    FileInfo[] languageFileInfoArray = directoryInfo.GetFiles(STR_LANGUAGE_FILTER);

    SPWeb web;
    for (int n = 0; n < languageFileInfoArray.Length; n++)
    {
     FileInfo fileInfo = languageFileInfoArray[n];
     web = SPControl.GetContextWeb(this.Context);
     if (fileInfo.Name == (web.Language.ToString() + ".lng.xml"))
     {
      this._currentLanguage = web.Language.ToString();
     }
    }

    if (this._currentLanguage == "")
    {
     this._currentLanguage = "1033";
    }

    this._resourceFile = new XmlDocument();
    XmlTextReader reader = new XmlTextReader(this.Page.Server.MapPath(resources + "/" + this._currentLanguage + ".lng.xml"));
    this._resourceFile.Load(reader);
    reader.Close();

   }
   catch (Exception ex)
   {
    AddError(ex);
   }
  }

  private string GetResourceDirectory()
  {
   string resources = this.ClassResourcePath;
   int p = resources.ToLower().IndexOf("wpresources");
   string s = resources.Substring(1, p);
   p = s.LastIndexOf("/") + 1;
   if(p > 1) resources = resources.Substring(p, resources.Length-p);
   return resources;
  }

  /// <summary>
  /// Uses the Builder pattern to check and create lists if they're needed.
  /// </summary>
  private static void CheckAndBuildLists()
  {
   ListDirector director = new ListDirector();
   director.ConstructList(new GroupListBuilder());
   director.ConstructList(new UserListBuilder());
   director.ConstructList(new CategoryListBuilder());
   director.ConstructList(new ForumAccessListBuilder());
   director.ConstructList(new ForumListBuilder());
   director.ConstructList(new TopicListBuilder());
   director.ConstructList(new MessageListBuilder());
  }

  private static void UpdateCurrentUserVisitTime()
  {
   ForumApplication.Instance.CurrentUser.LastVisit = DateTime.Now;
   RepositoryRegistry.ForumUserRepository.Save(ForumApplication.Instance.CurrentUser);
  }

  private void InitializeApplication()
  {
   UrlQuery query = new UrlQuery(this.Page.Request.Url.ToString());
   ForumApplication.Instance.BasePath = SPEncode.UrlEncodeAsUrl(query.Url);
   ForumApplication.Instance.Title = this.Name;
   ForumApplication.Instance.ForumCache = this.Page.Cache;
   ForumApplication.Instance.ClassResourcePath = this.ClassResourcePath;
   ForumApplication.Instance.SpUser = SPControl.GetContextWeb(Context).CurrentUser;
   ForumApplication.Instance.AppPoolUser = SPControl.GetContextSite(Context).OpenWeb().CurrentUser;
   ForumApplication.Instance.SpWeb = SPControl.GetContextSite(Context).OpenWeb();
  }

  #endregion

  #region Public Methods

  public void AddError(Exception ex)
  {
   if (ex == null)
    return;
   ErrorList.Add(ex);
  }

  public override string LoadResource(string id)
  {
   string translatedResource;

   try
   {
    translatedResource = this._resourceFile.DocumentElement.SelectSingleNode(String.Format(STR_RESOURCE_STRING, id)).InnerText;
   }
   catch
   {
    translatedResource = string.Format("Error reading resource ID=\"{0}\".", id);
   }

            return translatedResource;
  }

  public void PersistProperties()
  {
   try
   {
    ForumApplication.Instance.SpWeb.AllowUnsafeUpdates = true;
    base.SaveProperties = true;
   }
   catch (Exception exception)
   {
    this.AddError(exception);
   }
  }

  #endregion
 }
}

Jul 1, 2009 at 2:39 PM
Edited Jul 2, 2009 at 9:16 AM

Hello,

i have the same Problem, can anyone Help me to fix. Only the Web Application Admin has access? I have no Visual Studio and i'm not a developer.

Regard

Chris

 

I can Fix my Problem.Thanks to Tequila00shots

But one question is open, the Permission "List Permission --> Manage Lists" allowed the user to create a Document Libary. This is in my Solution undisired, can i stop it?

 

Oct 29, 2009 at 12:51 PM

Thanks shocksll.

Your solution works for me!

How to make it work, step by step (i assume that you installed the slution before and now you are only changing):

1. Open project with vs 2008.

2. Remove UnitTest from solution (i had some problems with it)

3. Create new key and sign project with that key.

4. Make changes to SharePointWebPart.cs (at the end, i will put code that works for me)

5. Compile and copy created dll to assembly. (check the public key, and copy it)

6. Change the publickey in web.config, and SharePointForums.dwp (before uploading it)

7. in C:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources\BilSimser.SharePoint.WebParts.Forums creates folder "1.2.0.0__"Your copied public key"

8. copy 1033.lng.xml to this directory (could be from 1.2.0.0__e516dadc23877c32), open the file and change public key

9. restart iis and that should be it

 

 

code:

#region Using Directives

using System;
using System.ComponentModel;
using System.Threading;
using System.Web.UI;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Collections;
using System.Text;
using BilSimser.SharePoint.Common.Service;
using BilSimser.SharePoint.WebParts.Forums.Controls;
using BilSimser.SharePoint.WebParts.Forums.Controls.Base;
using BilSimser.SharePoint.WebParts.Forums.Core.Service.Application;
using BilSimser.SharePoint.WebParts.Forums.Core.Service.Builders;
using BilSimser.SharePoint.WebParts.Forums.Utility;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

#endregion

namespace BilSimser.SharePoint.WebParts.Forums
{
 [ToolboxData("<{0}:SharePointForumWebPart runat=server></{0}:SharePointForumWebPart>")]
 [XmlRoot(Namespace="BilSimser.SharePoint.WebParts.Forums")]
 public class SharePointForumWebPart : WebPart
 {
  #region Fields

  private const string STR_RESOURCE_STRING = "/strings/string[@id='{0}']";
  private const string STR_LANGUAGE_FILTER = "*.lng.xml";
  private const string STR_DEFAULT_LANGUAGE = "1033";
  private const string STR_DEFAULT_FORUM_NAME = "Discussion Forums";

  private string _name = STR_DEFAULT_FORUM_NAME;
  private int _postCount = 0;
  private int _topicCount = 0;
  private int _forumCount = 0;
        private string _currentLanguage = STR_DEFAULT_LANGUAGE;
  private XmlDocument _resourceFile;
  private ArrayList _errorList = new ArrayList();

  #endregion

  #region Properties

  public ArrayList ErrorList
  {
   get { return _errorList; }
  }

  public bool IsValid
  {
   get { return ErrorList.Count == 0; }
  }

  [Category("Forum Properties")]
  [DefaultValue(STR_DEFAULT_FORUM_NAME)]
  [WebPartStorage(Storage.Shared)]
  [FriendlyNameAttribute("Forum Name")]
  [Description("Display name for your discussion forum.")]
  [Browsable(false)]
  public string Name
  {
   get { return _name; }
   set { _name = value; }
  }

  [Category("Forum Properties")]
  [DefaultValue(0)]
  [WebPartStorage(Storage.Shared)]
  [FriendlyNameAttribute("Post Count")]
  [Description("Number of posts in this forum.")]
  [Browsable(false)]
  public int PostCount
  {
   get { return _postCount; }
   set { _postCount = value; }
  }

  [Category("Forum Properties")]
  [DefaultValue(0)]
  [WebPartStorage(Storage.Shared)]
  [FriendlyNameAttribute("Forum Count")]
  [Description("Number of forums in this site.")]
  [Browsable(false)]
  public int ForumCount
  {
   get { return _forumCount; }
   set { _forumCount = value; }
  }

  [Category("Forum Properties")]
  [DefaultValue(0)]
  [WebPartStorage(Storage.Shared)]
  [FriendlyNameAttribute("Topic Count")]
  [Description("Number of topics in this forum.")]
  [Browsable(false)]
  public int TopicCount
  {
   get { return _topicCount; }
   set { _topicCount = value; }
  }

  #endregion

  #region Protected Methods

  protected override void OnInit(EventArgs e)
  {
   using (Identity.ImpersonateAppPool())
   {
    LoadResourceFileStrings();
    InitializeApplication();
    CheckAndBuildLists();
   }
  }

  protected override void OnLoad(EventArgs e)
  {
   /*
    * BUG: update isn't working
    *
   using (Identity.ImpersonateAppPool())
   {
    UpdateCurrentUserVisitTime();
   }
   */
  }

  protected override void RenderWebPart(HtmlTextWriter output)
  {
   if (output == null)
    return;

   try
   {
    EnsureChildControls();
    
    if(IsValid)
    {
     using (Identity.ImpersonateAppPool())
     {
      foreach (Control control in this.Controls)
      {
       control.RenderControl(output);
      }
     }
    }
    else
    {
     RenderError(output);
    }
   }
   catch (ThreadAbortException)
   {
    // this is thrown when the RSS feed completes so ignore it  
    // TODO: find a better way to render RSS so we don't throw the exception
   }
   catch (Exception unhandledException)
   {
    RenderError(output, unhandledException);
   }

            if (ForumApplication.Instance.SpWeb != null)
            {
                ForumApplication.Instance.SpWeb.Dispose();
            }

  }

  /// <summary>
  /// Notifies server controls that use composition-based implementation to create any child
  /// controls they contain in preparation for posting back or rendering.
  /// This will read in a QueryString called "control" and instantiate a server
  /// control with the same name then add that to the Web Parts controls.
  ///
  /// If no QueryString called "control" is found or invalid, we fall back to the
  /// basic <see cref="ViewForums"/> which just displays the default forum(s).
  /// </summary>
  protected override void CreateChildControls()
  {
   using (Identity.ImpersonateAppPool())
   {
    SharePointForumControls childControl;

    try
    {
     childControl = (SharePointForumControls) Enum.Parse(typeof (SharePointForumControls), Page.Request.QueryString["control"], true);
    }
    catch
    {
     childControl = SharePointForumControls.ViewForums;
    }

    BaseForumControl control = CreateDynamicForumControl(childControl);
    if(control != null)
     Controls.Add(control);
   }
  }

  private BaseForumControl CreateDynamicForumControl(SharePointForumControls childControl)
  {
   BaseForumControl control = null;
   
   try
   {
    string controlTypeName = string.Format("{0}.{1}", ForumConstants.Control_Namespace, childControl.ToString());
    Type controlType = Type.GetType(controlTypeName);
    control = Activator.CreateInstance(controlType) as BaseForumControl;
    control.WebPartParent = this;
   }
   catch(ArgumentNullException nullEx)
   {
    AddError(nullEx);
   }

   return control;
  }

  #endregion

  #region Private Methods

  public void RenderError(HtmlTextWriter output, Exception ex)
  {
   AddError(ex);
   RenderError(output);
  }

  private void RenderError(HtmlTextWriter output)
  {
   StringBuilder sb = new StringBuilder();
   foreach(Exception ex in ErrorList)
   {
    sb.AppendFormat("{0}<br>", ex.Message);
   }

   output.WriteLine("An error has occurred with the Forums Web Part.");
   output.WriteLine("See the details below for more information.</p>");
   output.WriteLine("<div class=\"ms-alerttext\">{0}</div>", sb.ToString());

   // TODO: get more system information to email
   output.WriteLine("</p><strong><a href=\"mailto:{0}?Subject=Forum Error&Body={1}\">Email error information to support</a></strong></p>", ForumConstants.Config_Author_Email, sb.ToString());
   output.WriteLine("<a href=\"{1}\">Return to {0} Home</a>", this.Name, ForumApplication.Instance.GetLink(SharePointForumControls.ViewForums));
  }

  private void LoadResourceFileStrings()
  {
   try
   {
    string resources = GetResourceDirectory();
    DirectoryInfo directoryInfo = new DirectoryInfo(this.Page.Server.MapPath(resources));
    FileInfo[] languageFileInfoArray = directoryInfo.GetFiles(STR_LANGUAGE_FILTER);

    SPWeb web;
    for (int n = 0; n < languageFileInfoArray.Length; n++)
    {
     FileInfo fileInfo = languageFileInfoArray[n];
     web = SPControl.GetContextWeb(this.Context);
     if (fileInfo.Name == (web.Language.ToString() + ".lng.xml"))
     {
      this._currentLanguage = web.Language.ToString();
     }
    }

    if (this._currentLanguage == "")
    {
     this._currentLanguage = "1033";
    }

    this._resourceFile = new XmlDocument();
    XmlTextReader reader = new XmlTextReader(this.Page.Server.MapPath(resources + "/" + this._currentLanguage + ".lng.xml"));
    this._resourceFile.Load(reader);
    reader.Close();

   }
   catch (Exception ex)
   {
    AddError(ex);
   }
  }

  private string GetResourceDirectory()
  {
   string resources = this.ClassResourcePath;
   int p = resources.ToLower().IndexOf("wpresources");
   string s = resources.Substring(1, p);
   p = s.LastIndexOf("/") + 1;
   if(p > 1) resources = resources.Substring(p, resources.Length-p);
   return resources;
  }

  /// <summary>
  /// Uses the Builder pattern to check and create lists if they're needed.
  /// </summary>
  private static void CheckAndBuildLists()
  {
   ListDirector director = new ListDirector();
   director.ConstructList(new GroupListBuilder());
   director.ConstructList(new UserListBuilder());
   director.ConstructList(new CategoryListBuilder());
   director.ConstructList(new ForumAccessListBuilder());
   director.ConstructList(new ForumListBuilder());
   director.ConstructList(new TopicListBuilder());
   director.ConstructList(new MessageListBuilder());
  }

  private static void UpdateCurrentUserVisitTime()
  {
   ForumApplication.Instance.CurrentUser.LastVisit = DateTime.Now;
   RepositoryRegistry.ForumUserRepository.Save(ForumApplication.Instance.CurrentUser);
  }

        //private void InitializeApplication()
        //{
        //    UrlQuery query = new UrlQuery(this.Page.Request.Url.ToString());
        //    ForumApplication.Instance.BasePath = SPEncode.UrlEncodeAsUrl(query.Url);
        //    ForumApplication.Instance.Title = this.Name;
        //    ForumApplication.Instance.ForumCache = this.Page.Cache;
        //    ForumApplication.Instance.ClassResourcePath = this.ClassResourcePath;
        //    ForumApplication.Instance.SpUser = SPControl.GetContextWeb(Context).CurrentUser;
        //    ForumApplication.Instance.AppPoolUser = SPControl.GetContextSite(Context).OpenWeb().CurrentUser;
        //    ForumApplication.Instance.SpWeb = SPControl.GetContextSite(Context).OpenWeb();
        //}

        private void InitializeApplication()
        {
            UrlQuery query = new UrlQuery(this.Page.Request.Url.ToString());
            using (SPSite site = new SPSite(SPControl.GetContextWeb(Context).Url))
            {
                SPWeb web = site.OpenWeb();
                ForumApplication.Instance.BasePath = SPEncode.UrlEncodeAsUrl(query.Url);
                ForumApplication.Instance.Title = this.Name;
                ForumApplication.Instance.ForumCache = this.Page.Cache;
                ForumApplication.Instance.ClassResourcePath = this.ClassResourcePath;
                ForumApplication.Instance.SpUser = SPControl.GetContextWeb(Context).CurrentUser;
                ForumApplication.Instance.AppPoolUser = web.CurrentUser;
                ForumApplication.Instance.SpWeb = web;
            }
        }

 


  #endregion

  #region Public Methods

  public void AddError(Exception ex)
  {
   if (ex == null)
    return;
   ErrorList.Add(ex);
  }

  public override string LoadResource(string id)
  {
   string translatedResource;

   try
   {
    translatedResource = this._resourceFile.DocumentElement.SelectSingleNode(String.Format(STR_RESOURCE_STRING, id)).InnerText;
   }
   catch
   {
    translatedResource = string.Format("Error reading resource ID=\"{0}\".", id);
   }

            return translatedResource;
  }

  public void PersistProperties()
  {
   try
   {
    SPWeb web = ForumApplication.Instance.SpWeb;
    SPFile file = web.GetFile(this.Context.Request.Path);
    SPWebPartCollection webPartCollection = file.GetWebPartCollection(Storage.Shared);
    web.AllowUnsafeUpdates = true;
    //this.SaveProperties = true;
    webPartCollection.SaveChanges(this.StorageKey);
   }
   catch (Exception ex)
   {
    AddError(ex); 
   }
  }

  #endregion
 }
}