0

How to response.redirect to a aspx page which is created on fly. Example:

Response.Redirect('<HTML><BODY>.....</BODY></HTML>");

I don't have any address to redirect. I am creating that aspx page after processing some logic and every time it is different. So want to redirect to the page which is created on fly without saving it somewhere.

Any input???

Eric Andres
  • 3,417
  • 2
  • 24
  • 40
usergaro
  • 417
  • 1
  • 6
  • 12

3 Answers3

1

You can't redirect to dymanic content like that. But maybe you could have your page load content via AJAX. Check out jQuery and its AJAX capabilities to load content into elements dynamically.

n8wrl
  • 19,439
  • 4
  • 63
  • 103
0

Have you thought about using an httpHandler for this?

In your web.config, register the handler:

<system.web>
 <httpHandlers>
   <add verb="*" path="PageBuilder.ashx" type="YourNamespace.ClassName, YourNamespace"/>
 </httpHandlers>
...

You can put whatever logic you currently have for building the aspx in your handler:

//use the IRequiresSessionState if your handler requires access to the session
public class PageBuilder : IHttpHandler, IRequiresSessionState 
{
    public void ProcessRequest(HttpContext context)
    {
        //logic to build your page
    }
}

Simply point your redirects to PageBuilder.ashx and pass the data either using querystring variables or with the Session object.

You can learn more about handlers here: What is an HttpHandler in ASP.NET

Community
  • 1
  • 1
TimDog
  • 8,758
  • 5
  • 41
  • 50
  • You mentioned in your question that you are 'processing some logic' that builds an aspx -- so this sounds like you are somehow dynamically building an aspx page based on some data...what you need to do is redirect to the .ashx BEFORE you build your .aspx and send the information you need to the handler so that it can create a dynamic page without the need for any physical aspx files. Does that help? – TimDog Jan 12 '12 at 22:27
0

Response.Redirect needs to be called before any HTML is emitted to the browser.

What I think you're trying to do is Response.Write out some HTML based on what happens in your processing. Are you sure you don't need a physical page or pages?

Tim
  • 4,051
  • 10
  • 36
  • 60