Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a custom HttpModule which purpose is to check the presence of a specific cookie. If the cookie is not present, an error message should appear in place of the page.

The http module works as expected on application pages and classic pages. However, when I navigate to a Wiki page, it stops working.

Basically, the module subscribes to the Page_Init event of the page, when the request targets a page :

    public void Init(HttpApplication context)
    {
        context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
    }

    private void context_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        HttpContext oContext = ((HttpApplication)sender).Context;

        var pageHandler = oContext.Handler as Page;
        if (pageHandler != null)
        {
            pageHandler.Init += new EventHandler(Page_Init);
        }
    }
    private void Page_Init(object sender, EventArgs e)
    {
          if(Check(HttpContext.Current))
          {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.Write("<div align='center' ><font face='Verdana' size='2'><p><br/><br/>" + sMessage + "</p></font></div>");
                HttpContext.Current.Response.End();
          }
    }

When the target is a wiki page, pageHandler is of kind TemplateRedirectionPage. The init subscription is done.

But the subscribed method is never called in the case of a wiki page.

What can cause this difference ? how to remedy ?

[Edit] A bit of progress, I found with ILSpy this code of the TemplateRedirectPage class :

    public new void ProcessRequest(HttpContext context)
    {
        try
        {
            IHttpHandlerFactory httpHandlerFactory = new TemplateRedirectionPage.DummyPageHandlerFactory();
            IHttpHandler handler = httpHandlerFactory.GetHandler(null, null, this.RedirectionUrl, null);
            handler.ProcessRequest(context);
        }
        catch (ThreadAbortException ex)
        {
            // omitted for clarity
        }
    }

I'm betting this "transfert" cause the page_init to never be called, as the actual handler is no more the original page handler.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.