从 Initialize() 取消控制器操作
我遇到过一种情况,我的控制器上有一些初始化代码,这可能会识别出需要一些用户交互的无效状态。
因此,如果发生这种情况,我想将客户重定向到另一个页面/操作。由于我不希望在遇到此无效状态时运行初始操作,因此我想取消包括该操作在内的整个请求。
这可能吗?我们已经发现解决这个问题的一种方法是使用一个 Filter,它从 Context.Items 中读取是否应该取消该操作,但是还有另一种更简单的方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我开始阅读本文并立即想到“上下文和过滤器”:-)
我认为这是最干净的方法...也就是说,您也可以执行
Which 内部抛出 ThreadAbortException 因此它会跳过所有其他代码。
I started reading this and immediately thought "Context and Filter" :-)
I think that is the cleanest way to do it... That said, you could also do
Which internally throws a ThreadAbortException so it skips all other code.