Archive

Archive for December, 2008

create an ISAPI plugin using c++

December 9th, 2008

Recently I was assigned a job to cange all the HTML pages in my company website to ASP pages. The site is very old that it had more than 2000 back links from other websites and we wanted a solution which will not change the page rank and search engine rankings.

Renaming the files and changing the internal links was not the best solution so we decided to create an ISAPI plugin to do the required job. All we required was an ISAPI plugin which should rewrite the .html url to .asp url.

ISAPIplugin can be developed only using C++. and C++ was new for me. Some qucik google search gave me the required information to start writing my own ISAPI filter plugin. Here is the sourcode for the plugin.

ISAPI.cpp

#include "stdio.h";
 
#include "stdlib.h";
 
#include "afx.h";
 
#include "afxisapi.h";
 
BOOL WINAPI __stdcall GetFilterVersion(HTTP_FILTER_VERSION *pVer)
 
{
 
pVer->dwFlags = (SF_NOTIFY_PREPROC_HEADERS | SF_NOTIFY_AUTHENTICATION |
 
SF_NOTIFY_URL_MAP  | SF_NOTIFY_SEND_RAW_DATA | SF_NOTIFY_LOG  | SF_NOTIFY_END_OF_NET_SESSION );
 
// You can subscribe to the notifications you require!
 
pVer->dwFilterVersion = HTTP_FILTER_REVISION;
 
return TRUE;
 
}
 
DWORD WINAPI __stdcall HttpFilterProc(HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType, VOID *pvData)
 
{
 
char buffer[256];
 
DWORD buffSize = sizeof(buffer);
 
HTTP_FILTER_PREPROC_HEADERS *p;
 
CHttpFilterContext *chc;
 
chc = (CHttpFilterContext *)pfc;
 
char *newUrl;
 
switch (NotificationType)  {
 
case SF_NOTIFY_PREPROC_HEADERS :
 
p = (HTTP_FILTER_PREPROC_HEADERS *)pvData;
 
BOOL bHeader = p->GetHeader(pfc,"url",buffer,&buffSize);
 
CString myURL(buffer);
 
if (myURL.Find(".html") != -1)
 
{
 
myURL.Replace(".html",".asp");
 
newUrl = myURL.GetBuffer(myURL.GetLength());
 
p->SetHeader(pfc, "url", newUrl);
 
}
 
return SF_STATUS_REQ_HANDLED_NOTIFICATION;
 
}
 
return SF_STATUS_REQ_NEXT_NOTIFICATION;
 
}

ISAPI.def

LIBRARY           "CDISAPI"
 
EXPORTS
 
HttpFilterProc
 
GetFilterVersion

[Post to Twitter]   [Post to Plurk]   [Post to Digg]   [Post to ping.fm]

Related posts

Shoban Uncategorized

How to get processor id (CPU’s ID) using Visual Basic.Net

December 9th, 2008

Some times we do need to find out the cpu’s id, which is unique for each CPU. This code example will help you to perform this task in vb.net.

To Execute the code, create a Visual Basic Windows Application in .Net; Add a button (“Button1”) in the form (“Form1”) then Implement the below given code in Form1.vb.

'Import following namespace
Imports System.Management
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        'Declare following three object variables
 
        Dim objMOS As ManagementObjectSearcher
        Dim objMOC As Management.ManagementObjectCollection
        Dim objMO As Management.ManagementObject
 
        'Now, execute the query to get the results
        objMOS = New ManagementObjectSearcher("Select * From Win32_Processor")
 
        objMOC = objMOS.Get
 
        'Finally, get the CPU's id.
        For Each objMO In objMOC
            MessageBox.Show("CPU ID = " & objMO("ProcessorID"))
        Next
 
        'Dispose object variables
 
        objMOS.Dispose()
        objMOS = Nothing
        objMO.Dispose()
        objMO = Nothing
 
    End Sub
End Class

[Post to Twitter]   [Post to Plurk]   [Post to Digg]   [Post to ping.fm]

Related posts

aby Uncategorized, vb.net

How to develop a facebook application

December 4th, 2008

Social snippets has written an excellent tutorial about writing your first Facebook Application using asp.net. Check it out here.

[Post to Twitter]   [Post to Plurk]   [Post to Digg]   [Post to ping.fm]

Related posts

Shoban ASP.net