Asp.net 2.0 按钮单击方法在网络花园中工作不一致

发布于 2024-08-08 03:44:14 字数 2090 浏览 10 评论 0原文

我们有一个在 IIS7 上运行的 asp.net 2.0 Web 应用程序。它使用网络花园和 asp.net 状态服务器。

在页面上,有许多用户控件。在其中一个用户控件上,我们添加了对 button_click 事件的日志记录,每当该方法运行时,该事件就会在日志中写入一行。当我们单击按钮时,它仅定期显示日志条目 - 表明单击按钮时并不总是触发事件。我们添加日志记录是因为我们怀疑当我们单击按钮时按钮单击方法并不总是运行。我们看到的证据似乎证实了我们的怀疑。

当我们删除网络花园并将站点放回单个应用程序池时,应用程序将恢复正常 - 每次都会触发按钮事件。当我们在本地开发者机器上运行应用程序时,它也可以正常运行。

还有其他人见过这样的行为吗?对于我们可以采取的后续步骤来缩小问题范围,有什么建议吗?

编辑:这里是请求的事件来源:

protected void btnSearch_Click(object sender, EventArgs e)
    {
        Log.Error("Searching...");

        SearchArgs args = CtrlToSearchArgs();
        SessionManager.SearchQueryString = Request.QueryString;

        string url = NavigationManager.BuildSearchUrl(args, null, "*** page url removed here ***");

        if (args.PageSize.HasValue)
        {
            SessionManager.SetInSession(SessionManager.Key.SEARCH_PAGESIZE, args.PageSize.Value.ToString());
        }
        else
        {
            SessionManager.SetInSession(SessionManager.Key.SEARCH_PAGESIZE, "10");
        }

        SessionManager.SearchPanelData = url;

        //Set the new args into the session
        SessionManager.SearchControlArgs = args;

        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Redirect(url);
    }

编辑#2:澄清 - 此设置不使用多个服务器,并且不在负载平衡器下。我们在单个服务器上使用多个应用程序池。

We have a asp.net 2.0 web application that is running on IIS7. It is using web gardens and asp.net state server.

On the page, there are many user controls. On one of the user controls, we have added logging on the button_click event that writes a line in the log whenever that method runs. When we click the button, it only periodically displays the log entry – indicating that the event does not always fire when the button is clicked. We added the logging because we suspected that the button click method was not always running when we clicked the button. The evidence we are seeing seems to confirm our suspicions.

When we remove the web garden and put the site back to a single application pool, the application returns to normal - the button event fires every time. When we run the application on local developer machines, it also works normally.

Has anyone else seen behavior like this? Are there any recommendations on next steps we could take to narrow down the problem?

EDIT: here is the source of the event as requested:

protected void btnSearch_Click(object sender, EventArgs e)
    {
        Log.Error("Searching...");

        SearchArgs args = CtrlToSearchArgs();
        SessionManager.SearchQueryString = Request.QueryString;

        string url = NavigationManager.BuildSearchUrl(args, null, "*** page url removed here ***");

        if (args.PageSize.HasValue)
        {
            SessionManager.SetInSession(SessionManager.Key.SEARCH_PAGESIZE, args.PageSize.Value.ToString());
        }
        else
        {
            SessionManager.SetInSession(SessionManager.Key.SEARCH_PAGESIZE, "10");
        }

        SessionManager.SearchPanelData = url;

        //Set the new args into the session
        SessionManager.SearchControlArgs = args;

        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Redirect(url);
    }

EDIT # 2: Clarification - this set up is not using multiple servers and is not under a load balancer. We are using multiple AppPools on a single server.

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

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

发布评论

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

评论(3

怀中猫帐中妖 2024-08-15 03:44:14

设置您的计算机密钥: http://msdn.microsoft.com/en-us /library/ms998288.aspx

当您没有指定计算机密钥时,这并不是唯一失败的情况,即如果重新启动应用程序池,生成的计算机密钥会发生更改,并且任何依赖于该计算机密钥的内容都会失败它即视图状态验证是一个,另一个: ASP.NET MVC Validation of ViewState MAC 失败

Set your machine key: http://msdn.microsoft.com/en-us/library/ms998288.aspx

This isn't the only scenario that fails when you don't have the machine key specified i.e. if the app pool is restarted the generated machine key changes and you get failures in anything that depends on it i.e. viewstate validation being one, another one: ASP.NET MVC Validation of ViewState MAC failed

旧竹 2024-08-15 03:44:14

您可能希望在负载均衡器上启用粘性会话。

以前我也遇到过类似的情况,页面是由服务器A渲染的,但是回发被发送到服务器B,导致回发验证失败。

或者,您可能还想手动设置 MachineKey,而不是使用粘性会话所有服务器都相同。

You probably want to enable sticky sessions on your load balancer.

In the past I have encountered a similar situation where the page was rendered by server A, but the postback was sent to server B causing a failure to validate the postback.

Alternatively, instead of using sticky session you may also want to look into manually setting your MachineKey to be the same for all servers.

捎一片雪花 2024-08-15 03:44:14

感谢弗雷迪和杰森发布答案。

在故障排除过程中,我们决定恢复为单个应用程序池。无论如何,这似乎是一种相当非正统的构建方式。然而,这也没有解决问题。

经过一番周折并让几个人检查代码后,我们终于发现会话中存储了一个包含静态变量的对象。我们解决了这个问题,网站开始按预期运行。

Thanks Freddy and Jason for posting answers.

During our troubleshooting process, we decided to revert back to a single app pool. It seemed like a pretty unorthodox way to structure things anyway. However, that didn't fix the problem either.

After going around and around and having a few people go over the code, we finally discovered that we had an object stored in session that contained static variables. We fixed that problem and the site started working as expected.

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