SqlSiteMapProvider - OnSiteMapChanged 事件永远不会触发?

发布于 2024-08-17 02:33:20 字数 1110 浏览 2 评论 0原文

我正在执行 SqlSiteMapProvider 的 Wicked Code 实现,但在 VB 中除外。网。

代码中有一些问题导致了问题,我不明白它应该如何按照文章中编写的方式工作。我直接从下面提供的文章中提供了代码。 我已将代码粘贴到此处以便于查看

第一个问题 - 依赖关系在之前实例化(第 134 行) -137) 树被创建 (151-160) - 因此一旦将依赖项添加到 http.cache (165-167),OnSiteMapChanged 事件 (242) 就会立即触发 - 使整个过程再次运行 - 这循环很多次,直到最后有东西让它停止。 (在我放弃尝试猜测最后一次命中之前,我单步执行并计算了代码循环至少 20 次)

好的,所以为了解决这个问题,我只是将代码移动到在构建树之后创建依赖项,就在插入到 http.cache 之前(因此在添加到 http.cache 时 HasChanged 属性为 false,并且您不会陷入这个伪无限循环)。

但我仍然有一个问题 - 每次加载页面时,BuildSiteMap()都会命中并且第121行检查 _root 是否不为空 - 似乎在第一次构建后它永远不会为空......这很好,因为我不每次都想击中数据库。现在,我将一条记录插入表中... OnSiteMapChanged 事件永远不会触发。当我浏览应用程序上的页面时,站点地图不会反映新插入的记录 - 单步执行代码,我发现第 121 行的检查仍然导致函数短路...站点地图只会在我重新刷新时刷新-启动 Visual Studio,这会导致私有 _root 字段再次变为 null,并重新构建站点地图,反映新的更改..(刷新浏览器或启动新的浏览器实例不起作用)...

编辑:问题源于我的存储过程顶部的愚蠢的“设置不计数”行。显然这破坏了查询通知。似乎该语句被视为结果集,而第二个实际查询语句使结果集无效,从而产生通知。在我添加注释之前,很难找到此内容,而且在 MSDN 文档中也找不到该内容。希望这可以拯救我所经历的守财奴!

I'm doing the Wicked Code implementation of SqlSiteMapProvider, except in VB.NET.

There's a few things with the code that are causing issues, and I don't understand how it is supposed to work the way it's written in the article. I've provided the code straight from the article provided below. I've pasted the code here for ease of viewing

First issue - the depedency is instantiated BEFORE (lines 134-137) the tree is created (151-160) - so as soon as you add the depedency to the http.cache (165-167), the OnSiteMapChanged event (242) fires immmediately - making the entire proccess run again - and this loops many times until finally something makes it stop. (i stepped through it and counted the code looping at least 20 times before I gave up on trying to guess when it hit last)

OK, so to fix this I just moved the code to the create the dependency to AFTER the tree is built, right before inserting to http.cache (so HasChanged property is false when adding to http.cache, and you don't get stuck in this psuedo-ifinite-loop).

I still have a problem though - every time a page loads, the BuildSiteMap() hits and line 121 checks if _root is not null - it seems it is never null after it is first built... this is good because I don't want to hit the DB each time. Now, I insert a record into the table... the OnSiteMapChanged event never fires. As I browse pages on the app, the sitemap does not reflect the newly inserted record - stepping through the code, I see that the check at line 121 is still causing the function to short circuit... The sitemap will only refresh if i re-start Visual Studio, which causes the private _root field to become null again, and re-builds the sitemap, reflecting the new changes.. (refreshing the browser or starting new browser instances does not work)...

EDIT: THE ISSUE STEMMED FROM A SILLY 'SET NOCOUNT ON' LINE IN THE TOP OF MY STORED PROC. APPARENTLY THIS BREAKS THE QUERY NOTIFICATION. It seems that this statement is seen as a result set and that the second, actual query statement invalidates the result set resulting in a notification. This was very hard to find and nowhere in the MSDN documentation until I added the comment. Hope this saves someone else the miser I went through!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两人的回忆 2024-08-24 02:33:20

该问题源于我的存储过程顶部的一条愚蠢的“设置不计数”行。显然这破坏了查询通知。似乎该语句被视为结果集,而第二个实际查询语句使结果集无效,从而产生通知。在我添加注释之前,很难找到此内容,而且在 MSDN 文档中也找不到该内容。希望这能拯救我所经历的守财奴的人!

THE ISSUE STEMMED FROM A SILLY 'SET NOCOUNT ON' LINE IN THE TOP OF MY STORED PROC. APPARENTLY THIS BREAKS THE QUERY NOTIFICATION. It seems that this statement is seen as a result set and that the second, actual query statement invalidates the result set resulting in a notification. This was very hard to find and nowhere in the MSDN documentation until I added the comment. Hope this saves someone else the miser I went through!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文