473,839 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filter output by using a HttpModule

I want to be able to implement a filter that manipulates the output from the
server... Maybe replacing some words, or highlighting a search string, or
some other fancy feature...

I want to make this code reusable to all my applications, and by making this
as a HttpModule I can implement this feature on existing .Net applications
by editing the we.config and nothing else...

My problem is that that I can't get this to work.

Some pseudo-code:

public class PostProcessingM odule : System.Web.IHtt pModule {
public void Init(System.Web .HttpApplicatio n context) {
// What event should i use ....
// How do I reference the output and replace values
// How do I write my own manipulated stuff to the client
}

public void Dispose() {}

}
Nov 18 '05 #1
4 1812
example here

http://flaky.dk/aspnet_httpmodule_charrewrite.html

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Thomas" <ne**********@o pcon.no> wrote in message
news:O8******** *****@TK2MSFTNG P11.phx.gbl...
I want to be able to implement a filter that manipulates the output from the server... Maybe replacing some words, or highlighting a search string, or
some other fancy feature...

I want to make this code reusable to all my applications, and by making this as a HttpModule I can implement this feature on existing .Net applications
by editing the we.config and nothing else...

My problem is that that I can't get this to work.

Some pseudo-code:

public class PostProcessingM odule : System.Web.IHtt pModule {
public void Init(System.Web .HttpApplicatio n context) {
// What event should i use ....
// How do I reference the output and replace values
// How do I write my own manipulated stuff to the client
}

public void Dispose() {}

}

Nov 18 '05 #2
Thx!

This solves my problem... almost ;-)

What if I want to implement more than one filter... lets say I have a
SearchHighlight Module and a WordCensorModul e ... The Response object can
only supprt one filter... I was hoping to be able to do this directly from
the httpmodule, but maybe that is impossible...

"John Timney (Microsoft MVP)" <ti*****@despam med.com> wrote in message
news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
example here

http://flaky.dk/aspnet_httpmodule_charrewrite.html

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Thomas" <ne**********@o pcon.no> wrote in message
news:O8******** *****@TK2MSFTNG P11.phx.gbl...
I want to be able to implement a filter that manipulates the output from

the
server... Maybe replacing some words, or highlighting a search string, or some other fancy feature...

I want to make this code reusable to all my applications, and by making

this
as a HttpModule I can implement this feature on existing .Net applications by editing the we.config and nothing else...

My problem is that that I can't get this to work.

Some pseudo-code:

public class PostProcessingM odule : System.Web.IHtt pModule {
public void Init(System.Web .HttpApplicatio n context) {
// What event should i use ....
// How do I reference the output and replace values
// How do I write my own manipulated stuff to the client
}

public void Dispose() {}

}


Nov 18 '05 #3
I figured it out... still using Response.Filter

HttpResponse res = HttpContext.Cur rent.Response;

if ( res.ContentType == "text/html" ) {
res.Filter = new CensorFilter(re s.Filter);
res.Filter = new HightLightFilte r(res.Filter);
}

In fact there was nothing to figure out... It just works :-D
"Thomas" <ma******@opcon .no> wrote in message
news:OV******** ******@TK2MSFTN GP10.phx.gbl...
Thx!

This solves my problem... almost ;-)

What if I want to implement more than one filter... lets say I have a
SearchHighlight Module and a WordCensorModul e ... The Response object can
only supprt one filter... I was hoping to be able to do this directly from
the httpmodule, but maybe that is impossible...

"John Timney (Microsoft MVP)" <ti*****@despam med.com> wrote in message
news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
example here

http://flaky.dk/aspnet_httpmodule_charrewrite.html

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Thomas" <newsma******@o pcon.no> wrote in message
news:O8******** *****@TK2MSFTNG P11.phx.gbl...
I want to be able to implement a filter that manipulates the output
from
the
server... Maybe replacing some words, or highlighting a search string, or some other fancy feature...

I want to make this code reusable to all my applications, and by
making this
as a HttpModule I can implement this feature on existing .Net

applications by editing the we.config and nothing else...

My problem is that that I can't get this to work.

Some pseudo-code:

public class PostProcessingM odule : System.Web.IHtt pModule {
public void Init(System.Web .HttpApplicatio n context) {
// What event should i use ....
// How do I reference the output and replace values
// How do I write my own manipulated stuff to the client
}

public void Dispose() {}

}



Nov 18 '05 #4
Yes, you can do that. Or you can make seperate filters and force their
order of priority by their position in order in web.config.

Glad you have a resolution.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"Thomas" <ma******@opcon .no> wrote in message
news:eD******** ******@TK2MSFTN GP12.phx.gbl...
I figured it out... still using Response.Filter

HttpResponse res = HttpContext.Cur rent.Response;

if ( res.ContentType == "text/html" ) {
res.Filter = new CensorFilter(re s.Filter);
res.Filter = new HightLightFilte r(res.Filter);
}

In fact there was nothing to figure out... It just works :-D
"Thomas" <ma******@opcon .no> wrote in message
news:OV******** ******@TK2MSFTN GP10.phx.gbl...
Thx!

This solves my problem... almost ;-)

What if I want to implement more than one filter... lets say I have a
SearchHighlight Module and a WordCensorModul e ... The Response object can
only supprt one filter... I was hoping to be able to do this directly from
the httpmodule, but maybe that is impossible...

"John Timney (Microsoft MVP)" <ti*****@despam med.com> wrote in message
news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
example here

http://flaky.dk/aspnet_httpmodule_charrewrite.html

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Thomas" <newsma******@o pcon.no> wrote in message
news:O8******** *****@TK2MSFTNG P11.phx.gbl...
> I want to be able to implement a filter that manipulates the output from the
> server... Maybe replacing some words, or highlighting a search
string, or
> some other fancy feature...
>
> I want to make this code reusable to all my applications, and by

making this
> as a HttpModule I can implement this feature on existing .Net

applications
> by editing the we.config and nothing else...
>
> My problem is that that I can't get this to work.
>
> Some pseudo-code:
>
> public class PostProcessingM odule : System.Web.IHtt pModule {
> public void Init(System.Web .HttpApplicatio n context) {
> // What event should i use ....
> // How do I reference the output and replace values
> // How do I write my own manipulated stuff to the client
> }
>
> public void Dispose() {}
>
> }
>
>



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2604
by: Jon Maz | last post by:
Hi All, I've been looking into options for URL Rewriting in .net, and to be honest, I haven't seen anything that's easier than the old Classic Asp solution with an ISAPI filter redirecting to an .asp page with responsibility for handling the redirect. I'm now planning to use this solution with my next .net project, and was wondering if anyone else out there has done this already, and what problems (if any) arise. Hopefully the news...
7
2583
by: nail | last post by:
Folks, I develop a HttpModule and it works correct, but one problem is occurs. After I register the httpmodule in the web.config, my pages (not testing http://localhost/site but http://my_machine_name/site) show problems when refresh the page. I guess some kind of javascript problems with the postback methods. Someone has any idea how can i fix it? Thanks
1
2250
by: Brian Norman | last post by:
Hello Can anyone suggest a way to read the response (I want to write it to a file) in an HttpModule but without using a response filter? I can't see any other way to get at the response stream. Thanks Brian Norman
2
2146
by: Simon-Pierre Jarry | last post by:
Hi, I created a custom HttpModule for managing the security of my application. in "Init" sub, I regsiter the events doing that : Public Sub Init(ByVal context As System.Web.HttpApplication) Implements IHttpModule.Init httpApp = context
2
1690
by: Daves | last post by:
think the subject says it all, my domain www.domain.com now is running asp.net but still gets requests to asp pages which were there on the old server. Can I create some global http filter to redirect all .asp requests to the default.aspx page?
0
2881
by: mpdoreilly | last post by:
Hi, I've a webservice that has several typical webmethods that clients call and get responses from. (Side note: The websriivce is actually to implement the server side of tr-069, the protocol is somewhat funny in that the server can send arbitrary requests to the client in the RESPONSES to calls to its webmethods)
2
1624
by: Josh Naro | last post by:
I am writing a module that requires the entire output from a web app to perform its function. So, basically I need to be able to pull the entire output stream from the Response object. I've tried attaching a custom filter to Response.Filter, but the custom filter receives the stream in separate chunks. I need the entire stream at once in order to convert it to an XmlDocument. Does anyone know of a way to get the entire output stream from a...
1
6491
by: lu2vik | last post by:
Hi, I would like to change the outputstream from response in the EndRequest httpmodule event. I tried whith the Response.Filter properties it works in the BeginRequest but not in the EndRequest. I don't understand why ...
2
1845
by: Ken Fine | last post by:
I have a question about ASP.NET output caching. I want to use screen scraping as a temporary hack to pull in some complex Classic ASP-rendered content into some ASP.NET pages: protected String ReadHtmlPage(string url) { WebResponse objResponse; WebRequest objRequest = System.Net.HttpWebRequest.Create(url); objResponse = objRequest.GetResponse();
0
9855
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10907
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10586
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10293
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7828
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7017
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3133
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.