Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ISAPI Filter? HOW?

Posted on 2001-06-16
5
Medium Priority
?
456 Views
Last Modified: 2011-05-11
Hello,

I am looking for a way to write a ISAPI filter in Delphi. Can anyone point me into a direction where to find examples and/or documentation on this matter.

Thanx.
0
Comment
Question by:mtieland
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 400 total points
ID: 6198058
0
 
LVL 17

Expert Comment

by:inthe
ID: 6198063
a funny example from a teamb member (nick h)
it sends all incoming requests from an MSIE client
to a virtual directory called /NoIE/

library browser;

uses
  Windows,
  SysUtils,
  ISAPI2;

const
  FilterDescription = 'An ISAPI filter that will not let Internet
Explorer into the site.';

function GetFilterVersion(var pVer : THTTP_FILTER_VERSION) : BOOL;
export; stdcall;
begin
  Result := True;
  try
    pVer.dwFlags :=        (SF_NOTIFY_SECURE_PORT
                         or SF_NOTIFY_NONSECURE_PORT
                         or SF_NOTIFY_PREPROC_HEADERS //This is what
we are interested in
                         or SF_NOTIFY_ORDER_LOW
                         );
    pVer.dwFilterVersion := HTTP_FILTER_REVISION;
    StrPCopy(pVer.lpszFilterDesc, FilterDescription);
  except
    Result := False;
  end;
end;

function HttpFilterProc( var pfc: THTTP_FILTER_CONTEXT;
                                  NotificationType : DWORD;
                                  pvNotification   : Pointer): DWORD;
export; stdcall;
var
  PreprocHeaders : THTTP_FILTER_PREPROC_HEADERS;
  Buffer: array[0..1024] of Char;
  BufferSize: DWORD;
  AgentStr, URL: string;
  aPos: Integer;
const
  sUserAgent = 'USER-AGENT:';
  sURL       = 'url';
  NewURL = '/NoIE/';  //Note -- the URL _must_ have a '/' on the end
by the end of this function

function NoIE: DWORD;
begin
  PreprocHeaders := THTTP_FILTER_PREPROC_HEADERS(pvNotification^);
//cast to proper record type
  BufferSize := SizeOf(Buffer);
  PreprocHeaders.GetHeader(pfc, sUserAgent, Buffer, BufferSize);
//Grab the URL.  It will be everything after the domain
  SetString(AgentStr, Buffer, BufferSize);
  if Pos('MSIE', AgentStr) > 0 then //if we are dealing with MSIE
  begin
    BufferSize := SizeOf(Buffer); //Reset Buffer for new use
    PreprocHeaders.GetHeader(pfc, sURL, Buffer, BufferSize);
    SetString(URL, Buffer, BufferSize);
    //Replace whatever the URL is with the /NoIE/ URL
    aPos := Pos('/', URL);
    Delete(URL, aPos, Length(URL) - aPos + 1);
    URL := Concat(URL, NewURL);
    //This sends out the new header and sents the request on its way
    PreprocHeaders.SetHeader(pfc, sURL, PChar(URL));
  end;
  Result := SF_STATUS_REQ_NEXT_NOTIFICATION;  //Means all done and
ready to go on
end;

begin
   case NotificationType of
       SF_NOTIFY_PREPROC_HEADERS : Result := NoIE;
     else
       Result := SF_STATUS_REQ_NEXT_NOTIFICATION;
     end;
end;

exports
  HttpFilterProc,
  GetFilterVersion;


end.
 
0
 
LVL 17

Expert Comment

by:inthe
ID: 6198078
he has a article here but im having diffuculty getting the page to load so dont kow if its still there or not:
www.xapxone.com/html/dl304.htm
0
 

Author Comment

by:mtieland
ID: 6198646
Exactly what I was looking for,

And a funny way of writing too...

Thanx a lot.

(Sorry for the others I can give points only once so the
first good answer gets the points)
0
 

Author Comment

by:mtieland
ID: 6201308
Something I found out about redirecting on the URL_MAP event:

res := 'Location: ' + 'http://www.mylink.com' + #13+#10+#13+#10;
TServerSupportFunc (pfc.ServerSupportFunc) (pfc, SF_REQ_SEND_RESPONSE_HEADER,pChar('302 Redirect'), Cardinal(PChar(res)) , 0);

The second line shows the way you should do the actual redirect!

Martijn
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question