Response.Redirect not ending execution

前端 未结 6 1296
再見小時候
再見小時候 2020-12-10 03:01

I have Default.aspx page, which inherits from BasePage.cs, which inherits from System.Web.UI.Page. BasePage is where I do some common things every page must do upon loading

相关标签:
6条回答
  • 2020-12-10 03:38

    Probably you are calling the Response.Redirect method inside a try{}catch{} block, try it by calling outside of this block and you'll see that it will not fail. More info: http://www.velocityreviews.com/forums/t72105-responseredirect-in-a-trycatch.html Hope this helps.

    0 讨论(0)
  • 2020-12-10 03:38

    I'm going to get down voted for this! Curse my ignorance...

    Obviously you could try adding the following line after the redirect (as pointed out by recursive),

    response.end()
    

    But maybe the reason the response.redirect is not immediately causing redirection is that you have response buffering on (the default) and the page processing is not ended until after the buffer is flushed. If this were true (and admittedly I'm to lazy too try) then adding the following line would also solve you problem.

    response.flush()
    
    0 讨论(0)
  • 2020-12-10 03:41

    You can throw an exception, that will exit code execution, but still redirect:

    HttpContext.Current.Response.Redirect("/login", true);
    throw new Exception("Unauthorized Access");
    
    0 讨论(0)
  • 2020-12-10 03:48

    For an unconditional termination, you could try a

    Response.End()
    
    0 讨论(0)
  • 2020-12-10 03:50

    The second parameter for Response.Redirect is endResponse, however the tooltip says 'Indicates whether execution of the current page should terminate'. This is misleading, because the execution of the page does not actually terminate when the variable is true. It will finish running any code. However what does happen differently, is the Render events are canceled, and the Response is immediately flushed with the object moved header.

    You need to manually exit out of any methods, Response.Redirect / Response.End will not do that for you. Futhermore, if you need a conditional to see if the Page has been redirected, check out Response.IsRequestBeingRedirected.

    0 讨论(0)
  • 2020-12-10 04:00

    are you exiting from the function that calls redirect, e.g.

    ...redirect(stopit,true);
    return;
    

    ?

    0 讨论(0)
提交回复
热议问题