Welcome to Singapore blogs
Sign in
Singapore blogs
Search Options
Search Everything
Search Development
Home
Hubs
DotText
chuacw
Cape of Good Hope
Development
Appeal Letters readers
YP School 2007 Alumni
chuacw
frove
frove
Technical
eCommerce
More ...
Blog - Monthly Archive List
Archives
October 2024
(1)
June 2024
(1)
December 2023
(1)
November 2023
(1)
April 2023
(1)
March 2023
(1)
February 2023
(3)
January 2023
(1)
December 2022
(1)
November 2022
(1)
October 2022
(1)
July 2022
(1)
April 2022
(1)
March 2022
(1)
November 2021
(1)
October 2021
(2)
September 2021
(1)
August 2021
(1)
July 2021
(1)
May 2021
(1)
March 2021
(1)
February 2021
(3)
January 2021
(1)
December 2020
(1)
November 2020
(2)
October 2020
(1)
September 2020
(2)
August 2020
(1)
July 2020
(1)
June 2020
(4)
May 2020
(2)
March 2020
(1)
January 2020
(1)
December 2019
(2)
September 2019
(1)
May 2019
(6)
April 2019
(1)
February 2019
(2)
January 2019
(2)
December 2018
(1)
October 2018
(3)
August 2018
(2)
May 2018
(4)
April 2018
(4)
March 2018
(1)
February 2018
(3)
January 2018
(2)
December 2017
(3)
November 2017
(6)
October 2017
(3)
August 2017
(2)
July 2017
(1)
June 2017
(1)
April 2017
(1)
March 2017
(1)
February 2017
(2)
January 2017
(4)
November 2016
(2)
October 2016
(2)
August 2016
(1)
May 2016
(3)
January 2016
(4)
December 2015
(2)
November 2015
(1)
October 2015
(3)
September 2015
(5)
June 2015
(1)
March 2015
(1)
February 2015
(1)
January 2015
(2)
December 2014
(1)
October 2014
(1)
September 2014
(2)
July 2014
(2)
June 2014
(1)
May 2014
(3)
April 2014
(1)
March 2014
(5)
February 2014
(7)
January 2014
(2)
December 2013
(3)
November 2013
(5)
October 2013
(2)
September 2013
(4)
August 2013
(7)
July 2013
(1)
June 2013
(5)
May 2013
(1)
April 2013
(3)
March 2013
(3)
December 2012
(1)
July 2012
(1)
June 2012
(6)
May 2012
(5)
April 2012
(6)
March 2012
(3)
February 2012
(6)
January 2012
(10)
December 2011
(5)
November 2011
(1)
August 2011
(3)
June 2011
(1)
May 2011
(10)
April 2011
(4)
March 2011
(5)
February 2011
(2)
January 2011
(3)
December 2010
(8)
November 2010
(4)
October 2010
(1)
September 2010
(1)
August 2010
(1)
July 2010
(2)
June 2010
(3)
May 2010
(2)
April 2010
(4)
February 2010
(7)
January 2010
(2)
November 2009
(2)
October 2009
(1)
September 2009
(1)
July 2009
(1)
June 2009
(4)
May 2009
(3)
April 2009
(4)
March 2009
(6)
February 2009
(3)
January 2009
(5)
December 2008
(9)
November 2008
(4)
October 2008
(1)
September 2008
(4)
August 2008
(4)
July 2008
(3)
June 2008
(1)
May 2008
(2)
April 2008
(6)
March 2008
(4)
February 2008
(1)
January 2008
(7)
December 2007
(1)
November 2007
(3)
October 2007
(1)
September 2007
(2)
August 2007
(5)
July 2007
(1)
April 2007
(2)
March 2007
(3)
February 2007
(1)
January 2007
(1)
November 2006
(1)
October 2006
(4)
August 2006
(1)
March 2006
(3)
January 2006
(1)
December 2005
(6)
November 2005
(4)
October 2005
(2)
September 2005
(4)
August 2005
(5)
July 2005
(4)
June 2005
(10)
May 2005
(6)
April 2005
(5)
March 2005
(14)
February 2005
(8)
January 2005
(11)
December 2004
(15)
November 2004
(13)
October 2004
(4)
September 2004
(7)
August 2004
(18)
July 2004
(16)
June 2004
(15)
May 2004
(39)
April 2004
(20)
March 2004
(11)
February 2004
(16)
January 2004
(16)
A simple IHttpModule redirector with Delphi
Home
Blog
Wiki
Chee Wee's discoveries and tech blog
Changing the world one line of code at a time...
Generic Content
About the author
Options
Share this
A simple IHttpModule redirector with Delphi
chuacw
Tue, 8 Feb 2005 @ 12:59 PM
Comments
0
Recently, I noticed that this
site
is referring to one of the images on my site, without viewing my site. That is to say, one of the forum contributors put a < IMG src="..." > that refers directly to an image stored on my blog.
Since this blog is based on DotText, and that DotText has a IHttpModule system for allowing HttpModules to hook onto the HTTP request mechanism, I decided to write a DotText plugin / addon, that would redirect all requests to my site to another site. This teaches me how to use the IHttpModule interface of the NET Framework.
The simple test would be this: If the referer contains 4042.com, then, redirect it to another URL. Since it's a first version, I decided to hardcode all the values inside, instead of retrieving it from web.config.
Then, in order to deploy it, I copy it to the Dottext bin directory, and added the following line into the HttpModules section of web.config:
<add name="BlockReferer" type="Dottext.RefererBlocker.TRefererBlocker, Dottext.RefererBlocker">
In the process, I found out that
declaring the "destructor Destroy" pattern
doesn't work as described on Allen's blog. And Allen's response is:
"
IHttpModule has its own Dispose method irrespective of IDisposable.. The compiler only works its magic on the IDisposable interface and not any descendants. It handles the mapping of Dispose to the destructor. For any other interfaces, you're on your own
."
Tsk... Tsk... These Microsofties! Can't they just inherit IDisposable when declaring IHttpModule, so that Borland can do their job properly?
unit
Dottext.RefererBlocker.RefererBlockerImpl;
interface
uses
System.Web;
type
TRefererBlocker =
class sealed
(System.Object, IHttpModule)
public
procedure
Dispose;
procedure
Init(context: HttpApplication);
procedure
BanReferer(Sender: System.Object; e: EventArgs);
end
;
implementation
{ TRefererBlocker }
procedure
TRefererBlocker.BanReferer(Sender: System.Object; e: EventArgs);
var
context: HttpApplication;
begin
context := HttpApplication(Sender);
if
Pos('4042.com', context.Request.UrlReferrer.ToString)<>0 then
context.Response.Redirect('http://www.microsoft.com/presspass/images/features/2002/07-15exchangeqa_l.jpg');
end
;
procedure
TRefererBlocker.Dispose;
begin
// Empty
end
;
procedure
TRefererBlocker.Init(context: HttpApplication);
begin
Include(context.BeginRequest, BanReferer);
end
;
end
.
0 Comments
Delphi for .NET
,
DotText development / enhancement articles
Your comment has been posted.
Close
Thank you, your comment requires moderation so it may take a while to appear.
Close
Leave a Comment
Name
Website
Comment
Post
Chee Wee's discoveries and tech blog
Subscribe via RSS
Sort by:
Most Recent
|
Most Views
|
Most Comments
Excerpt View
|
Full Post View
Chee Wee's discoveries and tech blog
An idea on unifying counselling and technical support...
Posted
over 15 years ago
by
chuacw
0
Comments
An idea has been germinating in my mind on how counselling and technical support can be unified and married up. Will probably write up further on this...
Chee Wee's discoveries and tech blog
What's a thread dump in layman terms?
Posted
over 15 years ago
by
chuacw
0
Comments
One of the rarer times when I have to translate computer lingo to English. When asked what's a thread dump, I responded: Me: A thread is a task given...
Chee Wee's discoveries and tech blog
C#, Delphi for .NET, Delphi Win32, Java and now Android...
Posted
over 15 years ago
by
chuacw
0
Comments
Years ago, I took Lutz Roeder's C# implementation of Digger and translated it into Delphi for Win32 and Delphi.NET at the same time, and designed a...
Chee Wee's discoveries and tech blog
Linus likes Microsoft a little...
Posted
over 15 years ago
by
chuacw
0
Comments
Linus likes Microsoft a little bit because of the fantastic song mixed by Microsoft Songsmith (the wording reminds me a bit of Borland's illfated ReportSmith...
Chee Wee's discoveries and tech blog
Constructing classes using class reference
Posted
over 15 years ago
by
chuacw
0
Comments
Polymorphic class creation in Java and in Delphi: Java Delphi Class t[] = {Class1.class, Class2.class} Class LClass = t[x].newinstance(); type TCommonClass...
Chee Wee's discoveries and tech blog
How to test for inheritance: Delphi and Java
Posted
over 15 years ago
by
chuacw
0
Comments
Testing for inheritance in Java and in Delphi: Java Delphi if (o instanceof T1) if o is T1 then
Chee Wee's discoveries and tech blog
Fidonet Nodelist 1991
Posted
over 15 years ago
by
chuacw
0
Comments
Stumbled across a piece of history while surfing the web - Fidonet Nodelist 1991. In 1991, I was Fidonet 6:600/321. Strangely, I was under the impression...
Chee Wee's discoveries and tech blog
/etc/gps.conf
Posted
over 15 years ago
by
chuacw
0
Comments
The GpsLocationProvider in Android reads /etc/gps.conf in order to determine the NTP server to poll. The default configuration is: NTP_SERVER=north-america...
Chee Wee's discoveries and tech blog
Still alive!
Posted
over 15 years ago
by
chuacw
0
Comments
He's alive! The Doc's alive! He's in the Old West, but he's alive! - Marty McFly, Back to the Future, Part II These days, I'm busy...
Chee Wee's discoveries and tech blog
More Android code written - Chee Wee's SMS Manager
Posted
over 15 years ago
by
chuacw
0
Comments
... Wrote more Android code in the previous 3 hours! Managing SMS automatically will be easier on the Android once I decide to publish my SMS application...
Page 32 of 67 (665 items)
«
30
31
32
33
34
»
Tags
Accomplishments
Adventures in Delphi 8
Android
Blockchain
C#
CodeGear
Community Server
Delphi
Delphi for .NET
Delphi for Win32
DotText development / enhancement articles
Experiments
General
Hacking
Java
Javascript
Latest rumours / news about Borland Delphi 2005
Movies CMS for Migration
My RSS Reader
Network
OTA
Projects / Businesses
Security
ToolsAPI
Windows