拦截*.aspx

发布于 2024-10-05 01:50:59 字数 548 浏览 3 评论 0 原文

我正在尝试拦截每个 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>

I'm trying to intercept every aspx requests. The interception works, but the page stay blank. What am I missing ?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不必在意 2024-10-12 01:50:59

您正在拦截页面请求,然后您不会对其执行任何操作。如果您期望看到某种输出,则必须对被传递的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

苄①跕圉湢 2024-10-12 01:50:59

你并没有真正拦截他们。这更像是劫持他们。每个 *.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 in global.asax.

指尖凝香 2024-10-12 01:50:59

我使用 IhttpHandler 接口来处理图像返回。

IHttpHandlerFactory 是我用来处理页面拦截的:

public class HttpCMSHandlerFactory : IHttpHandlerFactory
{
    // collects page name requested
    string pageName = Path.GetFileNameWithoutExtension(context.Request.PhysicalPath);
    // Add the page name to the context
    context.Items.Add("PageName", pageName);
    // I can still check if the page physically exists else pass on to my CMS handler: CMSPage.aspx
    FileInfo fi = new FileInfo(context.Request.MapPath(context.Request.CurrentExecutionFilePath));
    if (fi.Exists == false)
    {
        // if page doesnt exist context info is passed on to CMSPage to handle copy
        return PageParser.GetCompiledPageInstance(string.Concat(context.Request.ApplicationPath, "/CMSPage.aspx"), url, context);
    }
    else
    {
        // if page exist physical page is returned
        return PageParser.GetCompiledPageInstance(context.Request.CurrentExecutionFilePath, fi.FullName, context);
    }
}

查看我之前的帖子关于这个主题

I used the IhttpHandler interface to handle my image return.

The IHttpHandlerFactory is what I use to handle Page interception:

public class HttpCMSHandlerFactory : IHttpHandlerFactory
{
    // collects page name requested
    string pageName = Path.GetFileNameWithoutExtension(context.Request.PhysicalPath);
    // Add the page name to the context
    context.Items.Add("PageName", pageName);
    // I can still check if the page physically exists else pass on to my CMS handler: CMSPage.aspx
    FileInfo fi = new FileInfo(context.Request.MapPath(context.Request.CurrentExecutionFilePath));
    if (fi.Exists == false)
    {
        // if page doesnt exist context info is passed on to CMSPage to handle copy
        return PageParser.GetCompiledPageInstance(string.Concat(context.Request.ApplicationPath, "/CMSPage.aspx"), url, context);
    }
    else
    {
        // if page exist physical page is returned
        return PageParser.GetCompiledPageInstance(context.Request.CurrentExecutionFilePath, fi.FullName, context);
    }
}

check out my previous post on the subject

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文