HttpModules

P

Peter Morris

Hi, just learning C# ASP.Net programming, and there's something
I don't understand.

The book lists a program, and says to put in in the /bin directory,
plus a code fragment to insert into the web.config file. The book says
this will insert a comment with a timestamp at the start and end of any
web page in the directory.

In fact, all I get is an error page, objecting to the insert into
web.config.
I don't understand what's wrong.

The error message is
"File or assembly name SimpleModules, or one of its dependencies, was not
found."


Here's the code. The file is saved as "BeginEnd.cs"

-------------------------------------------
<configuration>
<system.web>
<httpModules>
<add type="SimpleModules.BeginEnd, SimpleModules"
name="BeginEnd" />
</httpModules>
</system.web>
</configuration>
---------------------------------------------

using System;
using System.Web;

namespace SimpleModules
{
/// <summary>
/// Summary description for BeginEnd.
/// <add type="SimpleModules.BeginEnd, SimpleModules" name="BeginEnd" />
/// </summary>
public class BeginEnd : IHttpModule
{
private HttpApplication mApplication;

public void Init(System.Web.HttpApplication application)
{
// Wire up beginrequest
application.BeginRequest += new System.EventHandler(BeginRequest);
// Wire up endrequest
application.EndRequest += new System.EventHandler(EndRequest);
// Save the application
mApplication = application;
}

public void BeginRequest(object sender, EventArgs e)
{
mApplication.Response.Write("<!-- Begin Request Time: " +
DateTime.Now.ToString("HH:mm:ss.fffffff") + " -->");
}

public void EndRequest(object sender, EventArgs e)
{
mApplication.Response.Write("<!-- End Request Time: " +
DateTime.Now.ToString("HH:mm:ss.fffffff") + " -->");
}

public void Dispose()
{
}

}
}
 
K

Ken Cox [Microsoft MVP]

Did you compile the file?

You'll want to put the BeginEnd.dll or SimpleModules.dll into the /bin
directory, not the .cs file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top