SuperSaiyan

I do all aspects related to high performance distributed web application system, such as RIA, Security, databse design and sql, javascript, c#, Asp.net, Software Factory. Among these, the database part is the key to performance.

导航

how to redirect from ashx httphandler

ashx httphandler, 对于处理一些向图片服务等等的还是蛮适合的. 不过, 如果该handler要求 authentication的话, 那么有时侯, 由于session 或者 cookie timeout, 你这时候要么是返回一个错误, 要么是重定向到一个自动login的页面去获得authentication cookie. The later options, is sometime a better choice. 但是, 在ashx 的processrequest 中, 由于asp.net本身的限制, 如果你直接使用 redirect, 就会导致asp.net throw exception, 由此, 就会向客户端返回一个500错误, 而不能实现重定向. 其实, 一个简单的办法就能解决问题, 那就是,
response.Redirect(loginUrl, false);  // 这个false, 告诉系统, 不结束当前处理流, 也就不抛异常.
然后, 再
context.ApplicationInstance.CompleteRequest();

这就ok了

这是我前一段时间碰到的一个小问题, 为别人遇到类似问题时候, 不再花时间研究解决方法, 就随便写两句.

posted on 2009-09-29 22:34  SuperSaiyan  阅读(622)  评论(0编辑  收藏  举报