拦截*.aspx
我正在尝试拦截每个 aspx 请求。拦截有效,但页面保持空白。我缺少什么?
namespace WebSite
{
public class Class1 : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
}
}
}
<system.webServer>
<handlers>
<add name="SampleHandler" verb="*"
path="*.aspx"
type="WebSite.Class1, WebSite"
resourceType="Unspecified" />
</handlers>
</system.webServer>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在拦截页面请求,然后您不会对其执行任何操作。如果您期望看到某种输出,则必须对被传递的httpcontext执行某种操纵。以下是在处理HTTPContext时可能会读的几篇文章。简而言之,如果您希望看到响应,则必须为其生成一些内容。
http://odetocode.com/Articles/112.aspx
和Page.Response?
You're intercepting the page request, then you're not doing anything with it. If you expect to see some sort of output, you have to perform some kind of manipulation to the HttpContext being passed in. Below are a couple of articles that might be decent reading when dealing with the HttpContext. In a nutshell, if you expect to see a response, you have to generate something to it.
http://odetocode.com/Articles/112.aspx
What is the difference between HttpContext.Current.Response and Page.Response?
http://www.c-sharpcorner.com/uploadfile/desaijm/asp.netposturl11282005005516am/asp.netposturl.aspx
你并没有真正拦截他们。这更像是劫持他们。每个 *.aspx 请求都将转到此处理程序,而不是实际的 *.aspx 页面。更合适的方法是查看
global.asax
中的Application_BeginRequest
处理程序。You're not really intercepting them. That's more like hijacking them. Every *.aspx request will go to this handler and not the actual *.aspx page. A more suitable method would be for you to look in the
Application_BeginRequest
handler inglobal.asax
.我使用 IhttpHandler 接口来处理图像返回。
IHttpHandlerFactory 是我用来处理页面拦截的:
查看我之前的帖子关于这个主题
I used the IhttpHandler interface to handle my image return.
The IHttpHandlerFactory is what I use to handle Page interception:
check out my previous post on the subject