Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ISAPI https redirect not working

10 views
Skip to first unread message

merrittr

unread,
Jun 25, 2009, 11:04:34 AM6/25/09
to
Hi All I am trying to build a rwrite ISAPI filter that will replace
the word ".oldserv."
whith ".ourserv." and then redirect the user to the new string. The
code below works for http connections I would like it to work for
https connections can you help?


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

#include "stdafx.h"
#include "redirector.h"
#define REDIRECT_TO "mail.ourserv.com/exchange"


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

CRedirectorFilter theFilter;
//robm
HANDLE m_hLogFile = INVALID_HANDLE_VALUE;
//robm

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

CRedirectorFilter::CRedirectorFilter()
{
}

CRedirectorFilter::~CRedirectorFilter()
{
// close the file
CloseHandle(m_hLogFile);
}

BOOL CRedirectorFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
{
CHAR rgchBuff[1024];
DWORD cb;
//robm
if (m_hLogFile == INVALID_HANDLE_VALUE)
{
m_hLogFile = CreateFileW(L"c:\\redirector1.log",
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
0,
NULL);

if (m_hLogFile != INVALID_HANDLE_VALUE)
{
if (SetFilePointer(m_hLogFile, 0, NULL, FILE_END) == (DWORD) -1L)
{
CloseHandle(m_hLogFile);
m_hLogFile = INVALID_HANDLE_VALUE;
}
else
{
CTime t = CTime::GetCurrentTime();
cb = wsprintf(rgchBuff, "--> log started %s\n", t.Format("%m/%d/%y
%H:%M:%S"));
DWORD cbWritten = 0;
WriteFile(m_hLogFile,
rgchBuff,
cb,
&cbWritten,
NULL);
}
}
}
//robm


// 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)
{
DWORD cb;
DWORD cbWritten = 0;
CHAR rgchBuff[1024];
char buffer[256], szTemp [256], buffer2[2048];

DWORD buffSize = sizeof(buffer);
DWORD buffSize2 = sizeof(buffer2);
BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "url", buffer,
&buffSize);

CTime t = CTime::GetCurrentTime();
pCtxt->GetServerVariable ("SERVER_NAME", buffer2,&buffSize2);
CString serverString(buffer2);
CString urlString(buffer);
urlString.MakeLower(); // for this exercise
serverString.MakeLower(); // for this exercise
cb = wsprintf(rgchBuff, "%s : outside %s %s\n",t.Format("%m/%d/%y
%H:%M:%S"), serverString, urlString);
WriteFile(m_hLogFile, rgchBuff, cb,&cbWritten, NULL);
if (serverString.Find("mail.oldserv") != -1) //we want to redirect
this file
{
serverString.Replace(".oldserv.",".ourserv.");
wsprintf (szTemp, "Location: https://%s\r\n\r\n",REDIRECT_TO);
pCtxt->ServerSupportFunction (SF_REQ_SEND_RESPONSE_HEADER,(PVOID)
"302 Redirect",(LPDWORD) szTemp,0);
wsprintf(rgchBuff, "%s : inside >%s< >%s<\n (%s)\n",t.Format
("%m/%d/%y %H:%M:%S"), serverString, urlString,szTemp);
WriteFile(m_hLogFile, rgchBuff, cb,&cbWritten, NULL);
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

David Wang

unread,
Jul 7, 2009, 6:02:54 AM7/7/09
to
Is there any reason why you cannot use the built in 302 Redirection
functionality in IIS?

Just set the redirection at the Website level for mail.oldserv.com to
mail.ourserv.com


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//

0 new messages