ASP.NET AJAX - 非同步的要求有单独的会话? [英] ASP.NET Ajax - Asynch request has separate session?

查看:139
本文介绍了ASP.NET AJAX - 非同步的要求有单独的会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在写一个保存搜索条件会话状态并执行一个asp.net的UpdatePanel里面的搜索的搜索应用程序。有时,当我们执行多个搜索先后在第二或第三的搜索有时会从第一组的搜索条件返回结果。

We are writing a search application that saves the search criteria to session state and executes the search inside of an asp.net updatepanel. Sometimes when we execute multiple searches successively the 2nd or 3rd search will sometimes return results from the first set of search criteria.

例子:我们的我们做了的约翰·史密斯查找第一个搜索 - >约翰史密斯显示结果。我们一起来看看上鲍勃·琼斯第二个搜索 - >约翰史密斯显示结果。

Example: our first search we do a look up on "John Smith" -> John Smith results are displayed. The second search we do a look up on "Bob Jones" -> John Smith results are displayed.

我们保存所有的搜索条件会话状态就像我说的,和会话状态读取它Ajax请求格式化数据库查询的内部。当我们把破发点,在VS一切表现正常,但没有他们,我们得到原始的搜索标准和结果。

We save all of the search criteria in session state as I said, and read it from session state inside of the ajax request to format the DB query. When we put break points in VS everything behaves as normal, but without them we get the original search criteria and results.

我的猜测是因为它们被保存在会议上,该Ajax请求某种程度上都有自己的会话,并保存标准的,然后每一次检索的标准,从该会议,但非异步的东西是能看到当标准被修改并保存相应地变为状态,但因为它们是从两个不同的会话中有什么被保存并读视差

My guess is because they are saved in session, that the ajax request somehow gets its own session and saves the criteria to that, and then retrieves the criteria from that session every time, but the non-async stuff is able to see when the criteria is modified and saves the changes to state accordingly, but because they are from two different sessions there is a disparity in what is saved and read.

:: 更详细地说明,没有附加的搜索条件通常是很好的做法查询字符串的建议,我同意这就是应该的,但是按照我们的要求,我不认为它作为可行的。他们希望让用户填写的输入控件点击搜索,没有页面重载,他们唯一看到的是页面上的进度指标,他们仍然有导航和当前页面上使用其他的功能的能力。如果我的标准添加到查询字符串,我必须做的另一个请求导致整个页面加载,这取决于搜索条件可能需要很长一段时间。这就是为什么我们使用Ajax调用执行搜索,为什么我们不造成另一个完整的页面请求.....我希望这个澄清的情况。

:: To elaborate more, there was a suggestion of appending the search criteria to the query string which normally is good practice and I agree thats how it should be but following our requirements I don't see it as being viable. They want it so the user fills out the input controls hits search and there is no page reload, the only thing they see is a progress indicator on the page, and they still have the ability to navigate and use other features on the current page. If I were to add criteria to the query string I would have to do another request causing the whole page to load, which depending on the search criteria can take a really long time. This is why we are using an ajax call to perform the search and why we aren't causing another full page request..... I hope this clarifies the situation.

推荐答案

有不正常的ASP.NET页面加载,回发,和ASP.NET AJAX部分回发之间的多个会话。我可以告诉你,肯定。

There are not multiple sessions between normal ASP.NET page loads, postbacks, and ASP.NET AJAX partial postbacks. I can tell you that with certainty.

而不是存储字符串的搜索会话,如何只直接使用搜索文本框的内容是什么?我想不出任何理由为什么你需要周围的洗牌它,因为这将在整个页面的生命周期呢。

Rather than storing the search string in the session, how about just using the search TextBox's contents directly? I can't think of any reason why you'd need to shuffle it around, since it will be available throughout the entire page lifecycle anyway.

最后,关于你的要求......用一个UpdatePanel做的没有的满足您的用户应该能够使用网页上的其他功能,如果这个功能也提出了部分回发的要求。只有一个局部回传可以在一个时代的进步。如果其他事件引发的,而你的搜索过程中,搜索请求将没有任何通知被取消。

Finally, concerning your requirements... Using an UpdatePanel does not fulfill the requirement that your users should be able to use other functionality on the page if that functionality also raises partial postbacks. Only one partial postback can be in progress at a time. If another event is raised while your search is in progress, the search request will be canceled without any notification.

使用页面方法或Web服务的搜索将是一个的的更快,更容易,更强大的做这件事的方式。我通常不插我自己的网站,但我想我的几个职位是完全相关的,你在做什么:

Using a page method or web service for the search would be a much faster, easier, and more robust way of doing it. I don't usually plug my own site, but I think a couple of my posts are exactly relevant to what you're doing:

您可以使用一个用户控件呈现通过Web服务(不是一个UpdatePanel非常快)的搜索结果:的http://encosia.com/2008/02/05/boost-aspnet-performance-with-deferred-content-loading/

You could use a user control to render the search results through a web service (very much faster than an UpdatePanel): http://encosia.com/2008/02/05/boost-aspnet-performance-with-deferred-content-loading/

或者,也可以返回搜索结果作为JSON和渲染在客户端(更快):http://encosia.com/2008/06/26/use-jquery-and-aspnet-ajax-to-build-a-client-side-repeater/

Or, you could return the search results as JSON and render that on the client side (even faster): http://encosia.com/2008/06/26/use-jquery-and-aspnet-ajax-to-build-a-client-side-repeater/

无论这些方法可以把你的搜索功能了部分回发范式,使之运行速度更快,使用更少的带宽和服务器资源,并没有preclude其他的UpdatePanel活动从同时发生。

Either of those methods could take your search functionality out of the partial postback paradigm, so that it runs faster, uses less bandwidth and server resource, and doesn't preclude other UpdatePanel activity from occurring concurrently.

这篇关于ASP.NET AJAX - 非同步的要求有单独的会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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