?
Solved

Redirect from a IHttpAsyncHandler

Posted on 2008-11-13
1
Medium Priority
?
929 Views
Last Modified: 2013-12-17
I've got the following class:

    public class FileAsyncHandler : IHttpAsyncHandler, IRequiresSessionState {

And I'm trying to redirect the user to a login page if they're not authenticated. I want to terminate execution and redirect. Sounds simple, right? Here's what I've tried so far inside a method called from BeginProcessRequest():

Response.Redirect("default.aspx", true);
// For some reason it steps right through this statement and continues down the page, even if I set endResponse to true.

Response.AddHeader("Location", "default.aspx");
Response.StatusCode = 301;
Response.End();
// Like Response.Redirect, this doesn't cause the page to stop executing.

Server.Transfer("default.aspx");
// This almost works, but gives me some strange errors on the page it tries to redirect. It's not a clean redirect.

Server.TransferRequest("default.aspx");
// Gives me an error about an integrated pipeline being required. I require a solution that will work within the ASP.NET properties as they are.


I'm guessing since it is IHttpAsyncHandler it is not the same as IHttpHandler and may require something unusual. I'm all out of ideas.
0
Comment
Question by:paulott
1 Comment
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 2000 total points
ID: 22957373
Hi paulott,
You can terminate the function instead, use "return" function.
eg:
protected void BeginProcessRequest(){
   Response.Redirect("default.aspx", true);
// For some reason it steps right through this statement and continues down the page, even if I set endResponse to true.

return;//<----Add this code

Response.AddHeader("Location", "default.aspx");
Response.StatusCode = 301;
Response.End();
// Like Response.Redirect, this doesn't cause the page to stop executing.

}
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question