|
|
ASP.NET Forum 中禁用含有子版块的版块后产生的"未将对象引用设置到对象的实例"异常的处理方法 |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
如果禁用了存在子版块的版块,将会出现如下的异常:
Message: 发生类型为 System.Web.HttpUnhandledException 的异常。
System.NullReferenceException: 未将对象引用设置到对象的实例。 at AspNetForums.Data.SqlDataProvider.GetForums(Int32 siteID, Int32 userID, Boolean ignorePermissions, Boolean mergePermissions) at AspNetForums.Data.SqlDataProvider.GetForums(Int32 siteID, Int32 userID, Boolean ignorePermissions) at AspNetForums.Forums.GetForums(ForumContext forumContext, Int32 userID, Boolean ignorePermissions, Boolean cacheable) at AspNetForums.Components.ForumContext.get_ForumLookupTable() at AspNetForums.Components.ForumContext.GetForumFromForumLookupTable(Int32 forumID) at AspNetForums.Controls.BreadCrumb.AddForum(Int32 forumID) at AspNetForums.Controls.BreadCrumb.CreateChildControls() at System.Web.UI.Control.EnsureChildControls() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain()
产生这个异常的代码是: SqlDataProvider.cs 文件中 第3223行 ((Forum) forums[f.ParentID]).Forums.Add(f);
当系统读取子版块信息时,会尝试从 forums 集合中取父版块的引用.此时,因为父版块已被禁用,并没有包含在 forums 中,从而就造成了异常的产生.
解决方案:
1.修改代码.
把SqlDataProvider.cs 文件中 第3222行 if (f.ParentID > 0) ((Forum) forums[f.ParentID]).Forums.Add(f); } 修改为: if (f.ParentID > 0 && forums[f.ParentID] != null) ((Forum) forums[f.ParentID]).Forums.Add(f); }
2.修改存储过程
因为小第属SQL低手,在此只提供建议,不做实施.![[:#]](http://forum.newtopworks.com/emoticons/emotion-16.gif)
可以通过修改存储过程 forums_Forums_Get 使其在取论坛信息的时候就不取禁用的版块的子版块.如果哪位大虾改好了希望可以告诉我一声. 
|
|
相关文章:相关软件: |
|