开发者

Response.Redirect("page.aspx") doesn't always work

In my application this code:

CreditsSubjectsNamesTeacherCount n = new CreditsSubjectsNamesTeacherCount();
Session["UserID"] = n.GenerateTeacherCountCrossRegions(txtStartYear.Text.CheckOnEmptyYear(), ((UserInformation)S开发者_运维百科ession["UserInformation"]).UserName);
Response.Redirect("page.aspx");

doesnt redirect if the method GenerateTeacherCountCrossRegions was executing for a long time(~ >10 min). What can cause this problem?

PS: added:

<httpRuntime executionTimeout="18000".. > but it didnt help.

Thank you.


The request has timed out. Response.Redirect sends an HTTP response asking the browser to request a different page - if the request has timed out at the browser, it won't accept this response.


The browser has stopped waiting for the page, so there is no longer a connection. The server just sends the redirect into void, where noone is listening.

Start the work in a separate thread, so that the response doesn't have to wait for it to complete. Redirect to a page that reloads occationally to check the status of the work, and redirect to the final page when the work is complete.

To communicate with the background thread you need an object that both threads has a reference to. You can store a reference to the object in a session variable so that the page checking the status has access to it.


The request will time out, so the browser will display an error rather than the expected page. Note that this will likely not happen while debugging, only on deployment.

For long running operations of this kind consider a different interface.

I've created a system where the analyzed data is sent by email to the user when it's been calculated: internally I've spawned off a BackgroundWorker thread to do the calculation that then uses a MailMessage to send the report as a PDF attachment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜