2

I have come across a scenario where I have some initialization code on my conrtoller, which might identify an invalid state which will demand some user interaction.

There for, I want to redirect the customer to another page/action if that occurs. Since I don't want the initial action to run if I hit this invalid state, I want to cancel the whole request including the action.

Is this possible? We have figured out that one way to solve it is to use a Filter which reads out from Context.Items if it should cancel the action, but is there another, easier way?

4

1 回答 1

2

我开始阅读这篇文章并立即想到“上下文和过滤器”:-)

我认为这是最干净的方法......也就是说,你也可以这样做

Context.UnderlyingContext.Response.Redirect("someotherurl");

它在内部抛出一个 ThreadAbortException,因此它会跳过所有其他代码。

于 2010-09-07T14:21:21.147 回答