这是本人写的一个iisap filter iis过滤器,我的程序是oblog的博客程序,oblog有一个专门的二级域名组件,本人找了一些vc++的资料开发了一个可以二级域名重定向的组件,但是一刷新网站,iis就出错了.我把代码发上来,请高人给指点一下.
// COUNTER.CPP - Implementation file for your Internet Server
//    counter Filter#include "stdafx.h"
#include  <afxcoll.h>
#include "counter.h"
#include <stdio.h>
#include <string.h>
#include <httpfilt.h>#define baseroot "E:\\hzvip\\oblog\\"
///////////////////////////////////////////////////////////////////////
// The one and only CWinApp object
// NOTE: You may remove this object if you alter your project to no
// longer use MFC in a DLL.CWinApp theApp;
static CStringArray strarray;
static CStringArray strdoma;
static CStringArray strcust;
AfxOleInit();///////////////////////////////////////////////////////////////////////
// The one and only CCounterFilter objectCCounterFilter theFilter;
///////////////////////////////////////////////////////////////////////
// CCounterFilter implementationCCounterFilter::CCounterFilter()
{
}CCounterFilter::~CCounterFilter()
{
}
//BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION *pVer)
BOOL CCounterFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
{
// Call default implementation for initialization
CHttpFilter::GetFilterVersion(pVer); // Clear the flags set by base class
//pVer->dwFilterVersion=PHTTP_FILTER_VERSION;
//pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
//pVer->dwFlags |= SF_NOTIFY_ORDER_LOW | SF_NOTIFY_URL_MAP;
pVer->dwFlags = SF_NOTIFY_URL_MAP | SF_NOTIFY_ORDER_HIGH;
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 CCounterFilter::OnUrlMap(CHttpFilterContext* pCtxt,
PHTTP_FILTER_URL_MAP pMapInfo)
{
return SF_STATUS_REQ_NEXT_NOTIFICATION;
}DWORD CCounterFilter::HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD dwNotificationType, LPVOID pvNotification) 
{
DWORD namelen = 255;
char svrname[255];
char phyfile[255];
*svrname = 0;
pfc->GetServerVariable(pfc,"SERVER_NAME",svrname, &namelen);
strcpy(phyfile,((PHTTP_FILTER_URL_MAP)pvNotification)->pszPhysicalPath+strlen(baseroot));
_strlwr(svrname);
if(strcmp(svrname,"www.oblog.com")==0)
{
sprintf(((PHTTP_FILTER_URL_MAP)pvNotification)->pszPhysicalPath,"E:\\hzvip\\oblog\\%s",phyfile);
}
else
{
if(strarray.GetSize()>0)
{
int n=0;
for(int i=0;i<strarray.GetSize();i++)
{
if(strdoma.GetAt(i).Compare(m_Rpl)==0||strcust.GetAt(i).Compare(m_custom)==0)
{
sprintf(((PHTTP_FILTER_URL_MAP)pvNotification)->pszPhysicalPath,"E:\\hzvip\\oblog\\u\\%s\\%s",strarray.GetAt(i),phyfile);
n=n+1;
break;
}
}
if(n=0)
sprintf(((PHTTP_FILTER_URL_MAP)pvNotification)->pszPhysicalPath,"E:\\hzvip\\oblog\\%s",phyfile);
}
else
{
try
{
m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
m_pConnection->ConnectionTimeout=3;///设置超时时间为3秒
m_pConnection->Open("driver={SQL Server};Server=127.0.0.1;DATABASE=oblog;UID=oblog;PWD=oblog","","",adModeUnknown);
}
catch(_com_error e)///捕捉异常
{
CATCH_ERROR;
return false;
}
//
m_custom.Format("%s",svrname);
m_Rpl.Format("%s",svrname);
int nRep=m_Rpl.Find("oblog");
if(nRep!=-1)
{
m_Rpl.Replace(".oblog.com","");
}
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
//CString tempstr;
m_strSQL="Select custom_domain,user_domain,user_folder from oblog_user order by userid desc";
m_pRecordset->Open((_variant_t)m_strSQL, _variant_t((IDispatch*)this->m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
//sprintf(((PHTTP_FILTER_URL_MAP)pvNotification)->pszPhysicalPath,"E:\\hzvip\\oblog\\u\\%s\\%s",((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("user_folder")),phyfile);
// tempstr.Format("%s,%s,%s",(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("custom_domain"),(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("user_domain"),(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("user_folder"));

strarray.Add((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("user_folder"));
strdoma.Add((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("user_domain"));
strcust.Add((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("custom_domain"));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
//m_pConnection->Close();
}
catch (_com_error e)
{
CATCH_ERROR;
return false;
}
}
}
return CHttpFilter::HttpFilterProc(pfc, dwNotificationType, pvNotification);
}DWORD CCounterFilter::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(CCounterFilter, CHttpFilter)
//{{AFX_MSG_MAP(CCounterFilter)
//}}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;
}****/