ASP.NET 服务器不会异步处理页面 [英] ASP.NET Server does not process pages asynchronously

查看:33
本文介绍了ASP.NET 服务器不会异步处理页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带按钮的页面,我想通过单击按钮异步加载 2 个数据网格和数据.

这是页面的代码,我使用 jquery 调用其他 2 个页面来生成 html.

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Solutions_CashCenter_StockManagement_Test_Test" %><asp:Content ID="Content2" ContentPlaceHolderID="cphCenter" Runat="Server"><style type="text/css">#等待 {位置:绝对;顶部:0像素;右:10px;宽度:200px;z-索引:1000;垂直对齐:中间;文字对齐:居中;背景:#febf00;显示:无;}</风格><script src='<%= ResolveUrl("../../../../Scripts/jquery-1.4.1.js") %>'type="text/javascript"></script><script type="text/javascript">$(函数(){$('#wait').ajaxStart(function () { $(this).show(); }).ajaxStop(function () { $(this).hide(); });$('input:button').live('click', loadData);});函数加载数据(){$.get("Source.aspx", {},功能(数据){$('#a1').html(数据);},"html");alert('此警报是异步的 (1st)');$.get("Source2.aspx", {},功能(数据){$('#a2').html(数据);},"html");alert('这个警报是异步的(第二个)');}<div id="test13"><input type="button" id="btnLoad" value="Load"/>

<div id="a1"></div><div id="a2"></div><div id="等待">请稍等 <img src="ajax-loading.gif"/></div></asp:内容>

然后我有 2 个 aspx 页面,Source1.aspx 和 Source2.aspx.它们只包含一个 gridDataView 和 OnLoad 事件中的少量代码.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Source.aspx.cs" Inherits="Solutions_CashCenter_StockManagement_Test_Source" %><form runat="服务器"><cc1:GridDataView runat="server" ID="gridTest" ></cc1:GridDataView><asp:SqlDataSource ID="dsTest" runat="server" ConnectionString="<%$ ConnectionStrings:WebPortalConnectionString %>"ProviderName="<%$ ConnectionStrings:WebPortalConnectionString.ProviderName %>"></asp:SqlDataSource></表单>

服务端:

Thread.Sleep(5000);dsTest.SelectCommand = "SELECT 'test1', 'test2', 'test3'";this.gridTest.DataSourceID = "dsTest";this.gridTest.DataBind();

第二页也一样,但网格的数据不同.

我的结果是两个警报同时发生,但是网格一个接一个地加载,即第一个网格在 5 秒后出现,然后第二个网格在 5 秒后出现.那是服务器实际上并没有同时处理它们.

我做错了什么,我应该如何根据需要组织所有工作?

解决方案

这是因为会话锁定了页面读取.
所以当一个页面正在加载时,会话锁定所有其余的请求,直到完成并发送页面.

为了让它工作,你需要以太来禁用这个页面上的会话,以太使用默认情况下没有会话锁定的处理程序.

相关问题:

尝试使 Web 方法异步
网络应用在处理另一个网络应用时被阻止关于共享同一会话
哪些 perfmon 计数器可用于识别 ASP.NET 瓶颈?
完全替换 ASP.Net 的会话

I have a page with button, and i want to load 2 data grids with data asynchronously by cliking the button.

This is the code of the page, I use jquery to make calls to other 2 pages that will yield me html.

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Solutions_CashCenter_StockManagement_Test_Test" %>
<asp:Content ID="Content2" ContentPlaceHolderID="cphCenter" Runat="Server">
<style type="text/css">
    #wait {
    position:absolute;
    top:0px;
    right:10px;
    width:200px;
    z-index:1000;
    vertical-align:middle;
    text-align:center;
    background: #febf00;
    display:none;
}
</style>
<script src='<%= ResolveUrl("../../../../Scripts/jquery-1.4.1.js") %>' type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $('#wait')
        .ajaxStart(function () { $(this).show(); })
        .ajaxStop(function () { $(this).hide(); });

        $('input:button').live('click', loadData);
    });

    function loadData() {
        $.get("Source.aspx", {},
        function (data) {
            $('#a1').html(data);
        },
        "html");

        alert('This alert is asynchronous (1st)');

        $.get("Source2.aspx", {},
        function (data) {
            $('#a2').html(data);
        },
        "html");

        alert('This alert is asynchronous (2nd)');
    }
</script>
<div id="test13">
    <input type="button" id="btnLoad" value="Load" />
</div>
<div id="a1"></div>
<div id="a2"></div>
<div id="wait">Please wait <img src="ajax-loading.gif" /></div>
</asp:Content>

Then I have 2 aspx pages, Source1.aspx and Source2.aspx. They only containe a gridDataView and little code in OnLoad event.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Source.aspx.cs" Inherits="Solutions_CashCenter_StockManagement_Test_Source" %>
<form runat="server">
<cc1:GridDataView runat="server" ID="gridTest" >
</cc1:GridDataView>
<asp:SqlDataSource ID="dsTest" runat="server" ConnectionString="<%$ ConnectionStrings:WebPortalConnectionString %>"
    ProviderName="<%$ ConnectionStrings:WebPortalConnectionString.ProviderName %>">
</asp:SqlDataSource>
</form>

Server-side:

Thread.Sleep(5000);
dsTest.SelectCommand = "SELECT 'test1', 'test2', 'test3'";
this.gridTest.DataSourceID = "dsTest";
this.gridTest.DataBind();

And the same for the second page, but with different data for the grid.

What I have in result is that both alerts happen at once, but the grids are loaded one after one, that is 1st grid appears after 5 seconds, and then second one appers after another 5 sec. That is the server does not actually process them concurrently.

What am I doing wrong and how should I organize all to work as I need?

解决方案

This is happens because the session locks the page reads.
So when the one page is loading, the session lock all the rest request until is finish and send the page.

To make it work you need ether to disabled the session on this pages, ether use handler that is not have by default session lock.

Relative questions :

Trying to make Web Method Asynchronous
Web app blocked while processing another web app on sharing same session
What perfmon counters are useful for identifying ASP.NET bottlenecks?
Replacing ASP.Net's session entirely

这篇关于ASP.NET 服务器不会异步处理页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆