异步页面和重定向 [英] async pages and redirect

查看:103
本文介绍了异步页面和重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在异步asp.net实现中进行重定向时遇到问题。

大部分时间都可以工作,但是当它不仅仅是挂起时,浏览器

永远不会获得任何返回页面。如果我在调试器下运行它,它运行正常,虽然每次都会遇到HttpException。


System.Web.HttpException被捕获

ErrorCode = -2147024809

Message ="与远程主机通信时出错。

错误代码是0x80070057。

Source =" System.Web"

StackTrace:

at

System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6 .FlushCore(Byte [] status,

Byte [] header,Int32 keepConnected,Int32 totalBodySize,Int32

numBodyFragments,IntPtr [] bodyFragments,Int32 [] bodyFragmentLengths,Int32

doneWithSession,Int32 finalStatus,Boolean& async)

at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedR esponse(Boolean

isFinal)

at System.Web.Hosting.ISAPIWorkerRequest.FlushRespons e(Boolean

finalFlush)
$ b $.b at System.Web.HttpResponse.Flush(Boolean finalFlush)

at System.Web.HttpResponse.Flush()

at System.Web.HttpResponse.End()

在System.Web.HttpResponse.Redirect(String url,Boolean endResponse)

at w2pagev.PageV.EndPage(IAsyncResult ar)in

G:\inetpub\wwwroot\w2pagev\page.asp x.vb:第100行

在EndEventHandler中捕获异常。

我正在使用AddOnPreRenderCompleteAsync来设置它。

I am having trouble doing a redirect in an async asp.net implemention.
Most of the time it works, but when it doesn''t it just "hangs", the browser
never gets any return page. If I run it under the debugger, it works fine,
though every so often I get a HttpException.

System.Web.HttpException was caught
ErrorCode=-2147024809
Message="An error occurred while communicating with the remote host. The
error code is 0x80070057."
Source="System.Web"
StackTrace:
at
System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6 .FlushCore(Byte[] status,
Byte[] header, Int32 keepConnected, Int32 totalBodySize, Int32
numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32
doneWithSession, Int32 finalStatus, Boolean& async)
at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedR esponse(Boolean
isFinal)
at System.Web.Hosting.ISAPIWorkerRequest.FlushRespons e(Boolean
finalFlush)
at System.Web.HttpResponse.Flush(Boolean finalFlush)
at System.Web.HttpResponse.Flush()
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at w2pagev.PageV.EndPage(IAsyncResult ar) in
G:\inetpub\wwwroot\w2pagev\page.aspx.vb:line 100

The exception is caught in the EndEventHandler.
I am using AddOnPreRenderCompleteAsync to set this up.


推荐答案

Hello Pb,


根据您的描述,您有一个ASP.NET页面,被配置为

异步执行并且它可以工作大部分时间,但偶尔会出现一些

错误,如下所示,对吗?
Hello Pb,

Based on your description, you have an ASP.NET page that is configured as
async execution and it works for most time but will occasionally raise some
error as below, correct?

>>>>>>>>> >>>>>>>>>>
>>>>>>>>>>>>>>>>>>>



System.Web.HttpException被捕获

ErrorCode = -2147024809

Message ="与远程主机通信时发生错误。

错误代码是0x80070057。

<<<<<<<<<<<<<<< <<<<<<<


到目前为止,我已经研究过,没有任何明确的ASP.NET问题

2.0异步页面执行。我认为这里的问题应该是应用程序

具体的代码逻辑。你会提供一些你的问题的代码逻辑

async页面,比如你在异步处理程序中做了什么,以及当你在
调用response.Redirect时。如果可能的话,您可以尝试将其简化为重现问题所需的

代码。


此外,您是否检查过问题是否发生在高压力

条件,如应用程序已经在高容量下强调请求执行或即使并发请求很少也会发生?

无论如何,如果您有任何其他发现,请随时告诉我。

我错过了这个


真诚,


Steven Cheng


Microsoft MSDN在线支持主管


====== ============================================


通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx


==================================== ==============


此帖子按原样提供。没有保证,也没有授予任何权利。

System.Web.HttpException was caught
ErrorCode=-2147024809
Message="An error occurred while communicating with the remote host. The
error code is 0x80070057."
<<<<<<<<<<<<<<<<<<<

So far as I''ve researched, there hasn''t any definite issue of the ASP.NET
2.0 Async page execution. I think the problem here should be application
code logic specific. Would you provide some code logic of your problem
async page, such as what you''ve done in the async handler, and when you
call the response.Redirect. If possible, you can try simplified it to the
code that is necessary to repro the problem.

In addition, have you checked whether the problem occurs at high stress
condition, such as the application has been stressed under high volume
request execution or will occur even if there is few concurrent requests?

Anyway, please feel free to let me know if you have any other finding or
anything I''ve missed on this

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


" Steven Cheng [MSFT]"写道:
"Steven Cheng[MSFT]" wrote:

Hello Pb,


根据您的描述,您有一个配置为<的ASP.NET页面br />
异步执行它大部分时间都有效,但偶尔会出现一些

错误,如下所示,对吗?
Hello Pb,

Based on your description, you have an ASP.NET page that is configured as
async execution and it works for most time but will occasionally raise some
error as below, correct?

>>>>>>>>>>>>>> >>>>>
>>>>>>>>>>>>>>>>>>



发现System.Web.HttpException

ErrorCode = -2147024809

消息=" ;与远程主机通信时发生错误。

错误代码是0x80070057。

<<<<<<<<<<<<<<< <<<<<<<


到目前为止,我已经研究过,没有任何明确的ASP.NET问题

2.0异步页面执行。我认为这里的问题应该是应用程序

具体的代码逻辑。你会提供一些你的问题的代码逻辑

async页面,比如你在异步处理程序中做了什么,以及当你在
调用response.Redirect时。如果可能的话,您可以尝试将其简化为重现问题所需的

代码。


此外,您是否检查过问题是否发生在高压力

条件,如应用程序已经在高容量下强调请求执行或即使并发请求很少也会发生?

无论如何,如果您有任何其他发现,请随时告诉我。

我错过了这个


真诚,


Steven Cheng


Microsoft MSDN在线支持主管


====== ============================================


通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx


==================================== ==============


此帖子按原样提供。没有保证,也没有授予任何权利。

System.Web.HttpException was caught
ErrorCode=-2147024809
Message="An error occurred while communicating with the remote host. The
error code is 0x80070057."
<<<<<<<<<<<<<<<<<<<

So far as I''ve researched, there hasn''t any definite issue of the ASP.NET
2.0 Async page execution. I think the problem here should be application
code logic specific. Would you provide some code logic of your problem
async page, such as what you''ve done in the async handler, and when you
call the response.Redirect. If possible, you can try simplified it to the
code that is necessary to repro the problem.

In addition, have you checked whether the problem occurs at high stress
condition, such as the application has been stressed under high volume
request execution or will occur even if there is few concurrent requests?

Anyway, please feel free to let me know if you have any other finding or
anything I''ve missed on this

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



我可能已经解决了我的问题,但是间歇性的很难知道

像这样的问题?|所以让我更好地描述它:


异步模型如下所示:

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load


Dim bh As New BeginEventHandler(AddressOf Me.BeginPage)

Dim eh As New EndEventHandler(AddressOf Me.EndPage)

Me.AddOnPreRenderCompleteAsync(bh,eh)

End Sub

函数BeginPage(ByVal src As Object, ByVal args As EventArgs,ByVal cb As

AsyncCallback,ByVal state As Object)As IAsyncResult


Trace.Write(" BeginPage:Thread#&& amp; ;

System.Threading.Thread.CurrentThread.GetHashCode()&" ;;"&

System.Threading.Thread.CurrentThread.IsThreadPool Thread)


Dim v As New vmstate

v.m_page = Me

v.m_config = m_config


Dim vrs As New viewmanagerstate(Context,cb,v)

m_vm =新的viewmanager(v rs)

Dim ts As New ThreadStart(AddressOf m_vm.start)

Dim thread As New Thread(ts)

thread.Start()


返回vrs

结束功能


Sub EndPage(ByVal ar As IAsyncResult)


尝试

Trace.Write(" EndPage:Thread#" &

System.Threading.Thread.CurrentThread.GetHashCode()&英寸; " &

System.Threading.Thread.CurrentThread.IsThreadPool线程)


Dim m_vrs as viewmanagerstate = CType(ar,viewmanagerstate)

If Not IsNothing(m_vrs.m_data.m_redirect)然后

m_redirect = m_vrs.m_data.m_redirect

''Response.Redirect(m_vrs.m_data.m_redirect,True)

结束如果

Catch ex As Exception

结束尝试

结束子

受保护的覆盖Sub OnPreRenderComplete(ByVal e As System.EventArgs)

MyBase.OnPreRenderComplete(e)


尝试

Trace.Write (OnPreRenderComplete:Thread#"&

System.Threading.Thread.CurrentThread.GetHashCode()&" ;;"&

System.Threading .Thread.CurrentThread.IsThreadPool线程)


如果不是IsNothing(m_redirect)那么

Response.Redirect(m_redirect,True)

结束如果

Catch ex As Exception

结束尝试

结束子


现在,我遗漏了viewmanagerstate的详细信息,但它是一个类,

实现了IAsyncResult。


所以在开始时,我分拆了一个新线程。这不是线程池线程

(这当然是重点)。


因此,如果我使用EndPage的Response.Redirect,则会出现问题。在我的新线程上下文中这将是

,也许那就是问题,

具有TRUE的Response.Redirect将中止线程(I认为)。发布后,

我将Redirect移动到OnPreRenderComplete,我们又回到了一个线程

池线程。


似乎在那里工作;我已经对它进行了测试,并且可以让它在之前打破

,但是我担心这个问题在这个

上下文中不太可能。很高兴从MSFT确认,EndPage中的

Response.Redirect不起作用并将其移动到

OnPreRenderComplete是要走的路。


如果有帮助,我可以提供更多我的实施细节。


I may have solved my problem, but ita??s hard to know with intermittent
problems like thisa?| so let me better describe it:

The async model is hooked up like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim bh As New BeginEventHandler(AddressOf Me.BeginPage)
Dim eh As New EndEventHandler(AddressOf Me.EndPage)
Me.AddOnPreRenderCompleteAsync(bh, eh)
End Sub
Function BeginPage(ByVal src As Object, ByVal args As EventArgs, ByVal cb As
AsyncCallback, ByVal state As Object) As IAsyncResult

Trace.Write("BeginPage: Thread #" &
System.Threading.Thread.CurrentThread.GetHashCode( ) & "; " &
System.Threading.Thread.CurrentThread.IsThreadPool Thread)

Dim v As New vmstate
v.m_page = Me
v.m_config = m_config

Dim vrs As New viewmanagerstate(Context, cb, v)
m_vm = New viewmanager(vrs)
Dim ts As New ThreadStart(AddressOf m_vm.start)
Dim thread As New Thread(ts)
thread.Start()

Return vrs
End Function

Sub EndPage(ByVal ar As IAsyncResult)

Try
Trace.Write("EndPage: Thread #" &
System.Threading.Thread.CurrentThread.GetHashCode( ) & "; " &
System.Threading.Thread.CurrentThread.IsThreadPool Thread)

Dim m_vrs As viewmanagerstate = CType(ar, viewmanagerstate)
If Not IsNothing(m_vrs.m_data.m_redirect) Then
m_redirect = m_vrs.m_data.m_redirect
''Response.Redirect(m_vrs.m_data.m_redirect, True)
End If
Catch ex As Exception
End Try
End Sub
Protected Overrides Sub OnPreRenderComplete(ByVal e As System.EventArgs)
MyBase.OnPreRenderComplete(e)

Try
Trace.Write("OnPreRenderComplete: Thread #" &
System.Threading.Thread.CurrentThread.GetHashCode( ) & "; " &
System.Threading.Thread.CurrentThread.IsThreadPool Thread)

If Not IsNothing(m_redirect) Then
Response.Redirect(m_redirect, True)
End If
Catch ex As Exception
End Try
End Sub

For now, I left out the details of viewmanagerstate, but it is a class that
implements IAsyncResult.

So in begin, I spin off a new thread. This is NOT a thread pool thread
(which of course is the whole point).

So the trouble occurs if I use Response.Redirect from EndPage. This will be
in my new threada??s context and perhaps thata??s the problem right there, the
Response.Redirect with TRUE will abort the thread (I think). After posting,
I moved the Redirect to OnPreRenderComplete, where we are back on a thread
pool thread.

It seems to work there; I have tested it and cana??t get it to break as
before, but I am concerned that the problem is just less likely in this
context vs. fixed. It would be great to confirm from MSFT that the
Response.Redirect in EndPage will not work and moving it to
OnPreRenderComplete is the way to go.

I can provide more details of my implementation if it would help.


" pb" < pb@newsgroups.nospamwrote in message

news:1B ****************************** **** @ microsof t.com ...
"pb" <pb@newsgroups.nospamwrote in message
news:1B**********************************@microsof t.com...

" Steven Cheng [MSFT]"写道:

异步模型如下所示:


Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load


Dim bh As New BeginEventHandler(AddressOf Me.BeginPage)

Dim eh As New EndEventHandler(AddressOf Me .EndPage)

Me.AddOnPreRenderCompleteAsync(bh,eh)

End Sub


函数BeginPage(ByVal src As Object,ByVal args As EventArgs,ByVal cb

As

AsyncCallback,ByVal state As Object)As IAsyncResult


Trace.Write(" BeginPage:Thread#"&

System.Threading.Thread.CurrentThread.GetHashCode()&" ;;"&

System.Threading.Thread。 CurrentThread.IsThreadPool线程)


Dim v As New vmstate

v.m_page = Me

v.m_config = m_config


Dim vrs As New viewmanagerstate(Context,cb,v)

m_vm = New vie wmanager(vrs)

Dim ts As New ThreadStart(AddressOf m_vm.start)

Dim thread As New Thread(ts)

thread.Start ()
"Steven Cheng[MSFT]" wrote:
The async model is hooked up like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim bh As New BeginEventHandler(AddressOf Me.BeginPage)
Dim eh As New EndEventHandler(AddressOf Me.EndPage)
Me.AddOnPreRenderCompleteAsync(bh, eh)
End Sub
Function BeginPage(ByVal src As Object, ByVal args As EventArgs, ByVal cb
As
AsyncCallback, ByVal state As Object) As IAsyncResult

Trace.Write("BeginPage: Thread #" &
System.Threading.Thread.CurrentThread.GetHashCode( ) & "; " &
System.Threading.Thread.CurrentThread.IsThreadPool Thread)

Dim v As New vmstate
v.m_page = Me
v.m_config = m_config

Dim vrs As New viewmanagerstate(Context, cb, v)
m_vm = New viewmanager(vrs)
Dim ts As New ThreadStart(AddressOf m_vm.start)
Dim thread As New Thread(ts)
thread.Start()



也许它在你没有包含的代码中,但我看不出是什么让你的

在你的线程开始执行之前完成请求的页面。

这将导致你的线程引用一个处于无效的状态的页面。也许是你的线程导致调用EndPage?


您正在使用此代码为自己创建一个主要的维护问题。

有你之所以没有看到很多ASP.NET代码的例子,那就是因为
会创建另一个线程。这并不意味着那样工作。


John

Maybe it''s in the code you didn''t include, but I don''t see what keeps your
page from completing the request before your thread even begins executing.
This will cause your thread to be referenceing a page which is in an invalid
state. Perhaps it''s your thread that caused the EndPage to be called?

You are creating a major maintenance headache for yourself with this code.
There is a reason why you don''t see many examples of ASP.NET code that
creates another thread. It''s not meant to work that way.

John


这篇关于异步页面和重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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