开发者

Intercepting *.aspx

开发者 https://www.devze.com 2023-01-28 08:53 出处:网络
I\'m trying to intercept ev开发者_StackOverflowery aspx requests. The interception works, but the page stay blank. What am I missing ?

I'm trying to intercept ev开发者_StackOverflowery 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>


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消