views:

14

answers:

0

I'm using an isapi filter to redirect request for http://testportal.com/sites/testsp/_layouts/AccessDenied.aspx to a message page i've placed at the root of the site called "/test_msg.aspx."

The filter works, if I set the filter to capture request going to "sites/testsp/_layouts/" but when i set it to "sites/testsp/_layouts/AccessDenied.aspx" is does not work. Any help would be appreciated.

// REDIRECTOR.CPP - Implementation file for your Internet Server
    //    redirector Filter

    #include "stdafx.h"
    #include "redirector.h"




    ///////////////////////////////////////////////////////////////////////
    // The one and only CRedirectorFilter object

    CRedirectorFilter theFilter;


    ///////////////////////////////////////////////////////////////////////
    // CRedirectorFilter implementation

    CRedirectorFilter::CRedirectorFilter()
    {
    }

    CRedirectorFilter::~CRedirectorFilter()
    {
    }

    BOOL CRedirectorFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
    {
        // Call default implementation for initialization
        CHttpFilter::GetFilterVersion(pVer);

        // Clear the flags set by base class
        pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;

        // Set the flags we are interested in
        pVer->dwFlags |= SF_NOTIFY_ORDER_HIGH | SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT
                 | SF_NOTIFY_PREPROC_HEADERS | SF_NOTIFY_END_OF_NET_SESSION;

        // Load description string
        TCHAR sz[SF_MAX_FILTER_DESC_LEN+1];
        ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
                IDS_FILTER, sz, SF_MAX_FILTER_DESC_LEN));
        _tcscpy(pVer->lpszFilterDesc, sz);
        return TRUE;
    }

    DWORD CRedirectorFilter::OnPreprocHeaders(CHttpFilterContext* pCtxt,
        PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo)
    {
        char buffer[256];
        DWORD buffSize = sizeof(buffer);
        BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "url", buffer, &buffSize); 
        CString urlString(buffer);
        urlString.MakeLower(); // for this exercise 


   //problem area!!!!!! ... insert url condition

        if(urlString.Find("sites/testsp/_layouts/AccessDenied.aspx") != -1)          {

        CString newurl = "/test_msg.aspx";

        newurl += urlString;

        urlString.Replace(urlString, newurl);



            char * newUrlString= urlString.GetBuffer(urlString.GetLength());
            pHeaderInfo->SetHeader(pCtxt->m_pFC, "url", newUrlString);
            return SF_STATUS_REQ_HANDLED_NOTIFICATION;
        }
    //we want to leave this alone and let IIS handle it
        return SF_STATUS_REQ_NEXT_NOTIFICATION;
    }

    DWORD CRedirectorFilter::OnEndOfNetSession(CHttpFilterContext* pCtxt)
    {
        // TODO: React to this notification accordingly and
        // return the appropriate status code
        return SF_STATUS_REQ_NEXT_NOTIFICATION;
    }

    // Do not edit the following lines, which are needed by ClassWizard.
    #if 0
    BEGIN_MESSAGE_MAP(CRedirectorFilter, CHttpFilter)
        //{{AFX_MSG_MAP(CRedirectorFilter)
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    #endif  // 0

    ///////////////////////////////////////////////////////////////////////
    // If your extension will not use MFC, you'll need this code to make
    // sure the extension objects can find the resource handle for the
    // module.  If you convert your extension to not be dependent on MFC,
    // remove the comments arounn the following AfxGetResourceHandle()
    // and DllMain() functions, as well as the g_hInstance global.

    /****

    static HINSTANCE g_hInstance;

    HINSTANCE AFXISAPI AfxGetResourceHandle()
    {
        return g_hInstance;
    }

    BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason,
                        LPVOID lpReserved)
    {
        if (ulReason == DLL_PROCESS_ATTACH)
        {
            g_hInstance = hInst;
        }

        return TRUE;
    }

    ****/