473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

IHttpModule Dispose

When is the IHttpModule Dispose driven ?....at application recycle time ?

I developed a test HttpModule to trace INIT, BeginRequest, EndRequest and
Dispose....and the Dispose never gets driven. After a while the INIT is
redriven however the Dispose was never driven.

I am trying to locate the best means to hook ASP.NET application recycling
...... Is IHttpModule Dispose a solution for this and if so how ?...... or
should I use IRegisterObject ?.... I have seen some web postings on
IRegisterObject.
--
Philip
May 18 '07 #1
8 2896
Hi,
you should find this link useful:
http://www.thescripts.com/forum/thread432974.html
Hope this helps
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Philip" wrote:
When is the IHttpModule Dispose driven ?....at application recycle time ?

I developed a test HttpModule to trace INIT, BeginRequest, EndRequest and
Dispose....and the Dispose never gets driven. After a while the INIT is
redriven however the Dispose was never driven.

I am trying to locate the best means to hook ASP.NET application recycling
..... Is IHttpModule Dispose a solution for this and if so how ?...... or
should I use IRegisterObject ?.... I have seen some web postings on
IRegisterObject.
--
Philip
May 18 '07 #2
Hi,
you should find this link also useful:
http://markitup.com/Posts/Post.aspx?...0-1f72437f7cd2
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Philip" wrote:
When is the IHttpModule Dispose driven ?....at application recycle time ?

I developed a test HttpModule to trace INIT, BeginRequest, EndRequest and
Dispose....and the Dispose never gets driven. After a while the INIT is
redriven however the Dispose was never driven.

I am trying to locate the best means to hook ASP.NET application recycling
..... Is IHttpModule Dispose a solution for this and if so how ?...... or
should I use IRegisterObject ?.... I have seen some web postings on
IRegisterObject.
--
Philip
May 18 '07 #3
Thanks much for the post.... however can you clarify when the IHttpModule
Dispose is driven ?....just curious
--
Philip
"Manish Bafna" wrote:
Hi,
you should find this link useful:
http://www.thescripts.com/forum/thread432974.html
Hope this helps
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Philip" wrote:
When is the IHttpModule Dispose driven ?....at application recycle time ?

I developed a test HttpModule to trace INIT, BeginRequest, EndRequest and
Dispose....and the Dispose never gets driven. After a while the INIT is
redriven however the Dispose was never driven.

I am trying to locate the best means to hook ASP.NET application recycling
..... Is IHttpModule Dispose a solution for this and if so how ?...... or
should I use IRegisterObject ?.... I have seen some web postings on
IRegisterObject.
--
Philip
May 18 '07 #4

How exactly are you tracing Dispose() ? Is it possible that Dispose()
is being called but whatever resources it's using to trace were
already disposed.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Fri, 18 May 2007 06:53:05 -0700, Philip
<ph****@softwareforever.comwrote:
>When is the IHttpModule Dispose driven ?....at application recycle time ?

I developed a test HttpModule to trace INIT, BeginRequest, EndRequest and
Dispose....and the Dispose never gets driven. After a while the INIT is
redriven however the Dispose was never driven.

I am trying to locate the best means to hook ASP.NET application recycling
..... Is IHttpModule Dispose a solution for this and if so how ?...... or
should I use IRegisterObject ?.... I have seen some web postings on
IRegisterObject.
May 18 '07 #5
Hi,
MSDN Documentation says following about IHTTPModule Dispose:
The Dispose method is called once—when the application terminates. You
should keep in mind that the application terminates and reinitializes not
only when the application or IIS restarts, but also when the Web.config
configuration file or a dependent assembly is modified in any way.
Although i have not tried but below article by EggHeadCafe shows how to hook
up IHTTPModule Dispose and how unhandled exceptions can be trapped through
IHTTPModule implementation.
http://www.eggheadcafe.com/articles/20060305.asp
Hope this helps.
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Philip" wrote:
Thanks much for the post.... however can you clarify when the IHttpModule
Dispose is driven ?....just curious
--
Philip
"Manish Bafna" wrote:
Hi,
you should find this link useful:
http://www.thescripts.com/forum/thread432974.html
Hope this helps
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Philip" wrote:
When is the IHttpModule Dispose driven ?....at application recycle time ?
>
I developed a test HttpModule to trace INIT, BeginRequest, EndRequest and
Dispose....and the Dispose never gets driven. After a while the INIT is
redriven however the Dispose was never driven.
>
I am trying to locate the best means to hook ASP.NET application recycling
..... Is IHttpModule Dispose a solution for this and if so how ?...... or
should I use IRegisterObject ?.... I have seen some web postings on
IRegisterObject.
--
Philip
May 18 '07 #6
Sam....thanks for your suggestion on the IHttpModule Dispose, however I am
99% certain it is NOT being driven. I have even tried "throwing an
exception" in the Dispose....and NOTHING. Yet, I can force an application
recycling by changing the web.config....and I will see a new INIT being
driven when I do this.

Code follows...

using System;
using System.Web;
using System.Web.Hosting;
using System.Collections;
using System.Text;
using System.IO;
public class HttpModuleTrace : IHttpModule
{
~HttpModuleTrace()
{
TraceIt("Finalizer");
}

public void Init(HttpApplication application)
{
TraceIt("Init");

application.BeginRequest += (new
EventHandler(this.Application_BeginRequest));
application.EndRequest += (new
EventHandler(this.Application_EndRequest));
application.Disposed += (new EventHandler(this.Application_Disposed));
}

public void Dispose()
{
TraceIt("Dispose");
}

private void Application_BeginRequest(Object source, EventArgs e)
{
TraceIt("Application_BeginRequest");

HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
context.Response.Write("<h1><font color=red>HelloWorldModule:
Beginning of Request</font></h1><hr>");
}

private void Application_EndRequest(Object source, EventArgs e)
{
TraceIt("Application_EndRequest");

HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
context.Response.Write("<hr><h1><font color=red>HelloWorldModule:
End of Request</font></h1>");
}

private void Application_Disposed(Object source, EventArgs e)
{
TraceIt("Application_Disposed");
}

private string GetTraceFilePath()
{
System.Web.HttpContext http = System.Web.HttpContext.Current;
return http.Request.PhysicalApplicationPath + "HttpModuleTrace.txt";
}

private void TraceIt(string TraceText)
{
using (StreamWriter sw = new StreamWriter(GetTraceFilePath(), true,
System.Text.Encoding.UTF8))
{
sw.WriteLine(DateTime.Now.ToString("d-MMM-yyyy HH:mm:ss.fff") +
" - " + TraceText);
sw.Flush();
sw.Close();
}
}
}

--
Philip
"Samuel R. Neff" wrote:
>
How exactly are you tracing Dispose() ? Is it possible that Dispose()
is being called but whatever resources it's using to trace were
already disposed.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Fri, 18 May 2007 06:53:05 -0700, Philip
<ph****@softwareforever.comwrote:
When is the IHttpModule Dispose driven ?....at application recycle time ?

I developed a test HttpModule to trace INIT, BeginRequest, EndRequest and
Dispose....and the Dispose never gets driven. After a while the INIT is
redriven however the Dispose was never driven.

I am trying to locate the best means to hook ASP.NET application recycling
..... Is IHttpModule Dispose a solution for this and if so how ?...... or
should I use IRegisterObject ?.... I have seen some web postings on
IRegisterObject.

May 18 '07 #7

I would suspect problem is here:

private string GetTraceFilePath()
{
HttpContext http = Current;
return http.Request.PhysicalApplicationPath +
"HttpModuleTrace.txt";
}

When Dispose is called I doubt there is a current context so you're
probably getting a null reference exception which gets subsequently
ignored because the module is being disposed and ASP.NET doesn't know
what to do with it.

Try logging to a hard coded absolute path instead of using HttpContext
and see if you get the disposed message then.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Fri, 18 May 2007 12:14:01 -0700, Philip
<ph****@softwareforever.comwrote:
>Sam....thanks for your suggestion on the IHttpModule Dispose, however I am
99% certain it is NOT being driven. I have even tried "throwing an
exception" in the Dispose....and NOTHING. Yet, I can force an application
recycling by changing the web.config....and I will see a new INIT being
driven when I do this.

Code follows...
....
>
private void Application_Disposed(Object source, EventArgs e)
{
TraceIt("Application_Disposed");
}

private string GetTraceFilePath()
{
System.Web.HttpContext http = System.Web.HttpContext.Current;
return http.Request.PhysicalApplicationPath + "HttpModuleTrace.txt";
}

private void TraceIt(string TraceText)
{
using (StreamWriter sw = new StreamWriter(GetTraceFilePath(), true,
System.Text.Encoding.UTF8))
{
sw.WriteLine(DateTime.Now.ToString("d-MMM-yyyy HH:mm:ss.fff") +
" - " + TraceText);
sw.Flush();
sw.Close();
}
}
}
May 18 '07 #8
Sam...thanks much....I can now see the Dispose in the trace.

--
Philip
"Samuel R. Neff" wrote:
>
I would suspect problem is here:

private string GetTraceFilePath()
{
HttpContext http = Current;
return http.Request.PhysicalApplicationPath +
"HttpModuleTrace.txt";
}

When Dispose is called I doubt there is a current context so you're
probably getting a null reference exception which gets subsequently
ignored because the module is being disposed and ASP.NET doesn't know
what to do with it.

Try logging to a hard coded absolute path instead of using HttpContext
and see if you get the disposed message then.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Fri, 18 May 2007 12:14:01 -0700, Philip
<ph****@softwareforever.comwrote:
Sam....thanks for your suggestion on the IHttpModule Dispose, however I am
99% certain it is NOT being driven. I have even tried "throwing an
exception" in the Dispose....and NOTHING. Yet, I can force an application
recycling by changing the web.config....and I will see a new INIT being
driven when I do this.

Code follows...

....

private void Application_Disposed(Object source, EventArgs e)
{
TraceIt("Application_Disposed");
}

private string GetTraceFilePath()
{
System.Web.HttpContext http = System.Web.HttpContext.Current;
return http.Request.PhysicalApplicationPath + "HttpModuleTrace.txt";
}

private void TraceIt(string TraceText)
{
using (StreamWriter sw = new StreamWriter(GetTraceFilePath(), true,
System.Text.Encoding.UTF8))
{
sw.WriteLine(DateTime.Now.ToString("d-MMM-yyyy HH:mm:ss.fff") +
" - " + TraceText);
sw.Flush();
sw.Close();
}
}
}

May 18 '07 #9

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

Similar topics

0
by: Nicholas Irving | last post by:
Hi all, I am having an issue with one of my HttpModules where I cannot get the application path on Init. What I would like to do is to the following public class wherefrom : IHttpModule {...
0
by: moid | last post by:
Sir we are implementing front controller in asp.net. we implement three event-handler 1. PreRequestHandlerExecute 2. PostRequestHandlerExecute 3. BeginRequest we just want to initialize...
2
by: Kenneth Myhra | last post by:
Hi, We have been trying to develop an IHTTPModule (that was supposed to replace or take over the ISAPI Filters, as far as we know). We have developed one in C# and it seems to be working. The...
2
by: silesius | last post by:
Hi all, I'm using Visual Studio to create an HttpModule. I created a class library project added my code and two directives System and System.Web, but every time I try to compile it gives me this...
6
by: Simone Busoli | last post by:
Hello, I am trying to understand when IHttpModule.Dispose method is called. Is it called when the Application is disposed, or when the request ends? If I want to make an object Application-wide...
1
by: Lloyd Dupont | last post by:
I'm trying to write a multilingual web site where the user could choose his language explicitely. I have 2 flag, the user could click on the flag to change the culture. The core of the logic goes...
0
by: John | last post by:
I am writing a custom httpmodule, I can catch BeginRequest, EndRequest event, But I can not catch Error event, I tried throwing an error from my Web Service, creating a security exception (by...
1
by: Eric Goforth | last post by:
Hello, I found a C# example on the web that used an httpmodule. I've translated it to VB.NET and the website compiles fine, but when I build the website the iHttpModule doesn't compile, I can't...
0
by: Jonathan Wood | last post by:
Greetings, So, I now have a custom IHttpModule class that I use to establish the Theme for each page, based on the user's settings. Seems to work just fine. Thanks to everyone who made helpful...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.