ASP.NET: What happens to code after Response.Redirect(…)?

前端 未结 4 1978
日久生厌
日久生厌 2021-02-03 18:31

Does Response.Redirect() cause the currently running method to abort? Or does code after Response.Redirect() execute also?

(That is, is it necessary to return/Exit Sub a

4条回答
  •  隐瞒了意图╮
    2021-02-03 19:20

    My understanding is that upon issuing a Response.Redirect(), code following it will not execute. If you think about it, it would make sense not to execute it. You're basically telling your code that you want to go somewhere else.

    Example: Think of it as ordering a value meal at McDonalds. After you order it and they start filling your drink, you change your mind and say "you know what, forget my order. I'm going to Redirect myself to Wendy's." At that point, they're going to stop making your fries and burger because, well... you've decided to go somewhere else -- i.e. redirecting the response.

提交回复
热议问题