When I add an httpModule to my application it does nothing different. I am trying a basic module to see how if it works and then building from there. I compile the module and call it TweakRequestModule.dll and put this in my bin directory. I used this line
to complie: vbc /sdkpath:d:\windows\microsoft.net\framework\v1.0.3705 /t:library /r:System.dll,System.Web.dll TweakRequestModule.vb I had to use the /sdkpath because the server is running an older version. It compiles without any errors. I then changed my
web.config file to read: Here is the Module: Imports System Imports System.Web Public Class TweakRequestModule Implements IHttpModule Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init AddHandler app.BeginRequest, AddressOf MyBeginRequest
AddHandler app.EndRequest, AddressOf MyEndRequest End Sub Public Sub Dispose() Implements IHttpModule.Dispose ' add clean-up code here if required End Sub Public Sub MyBeginRequest( ByVal s As Object, ByVal e As EventArgs ) Dim app As HttpApplication app =
CType(s, HttpApplication) app.Response.Write _ ("
Request Begins Here...
") End Sub Public Sub MyEndRequest(ByVal s As Object, ByVal e As EventArgs ) Dim app As HttpApplication app = CType(s, HttpApplication) app.Response.Write _ ("
The registration in your web.config file says look in: MyHttpModule[namespace].TweakRequestModules[classname], MyHttpModule[assemblyname]. I think you need to add the following to the command line: /out:MyHttpModule.dll so that you name the assembly properly
(otherwise i think it defaults to the name of the .vb file, which, in this case, is TweakRequestModules). Then you also need to add a namespace to the file since you are specifying it in the web.config file. So add Namespace MyHttpModule to the .vb file.
Still no luck. Here is what I have: Web.config TweakRequestModule.vb Imports System Imports System.Web Namespace MyHttpModule Public Class TweakRequestModule Implements IHttpModule Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init AddHandler
app.BeginRequest, AddressOf MyBeginRequest AddHandler app.EndRequest, AddressOf MyEndRequest End Sub Public Sub Dispose() Implements IHttpModule.Dispose ' add clean-up code here if required End Sub Public Sub MyBeginRequest( ByVal s As Object, ByVal e As EventArgs
) Dim app As HttpApplication app = CType(s, HttpApplication) app.Response.Write _ ("
Request Begins Here...
") End Sub Public Sub MyEndRequest(ByVal s As Object, ByVal e As EventArgs ) Dim app As HttpApplication app = CType(s, HttpApplication) app.Response.Write _ ("
Request Ends Here...
") End Sub End Class End Namespace I then compile this with the command line: vbc /sdkpath:d:\windows\microsoft.net\framework\v1.0.3705 /out:MyHttpModule.dll /t:library /r:System.dll,System.Web.dll TweakRequestModule.vb Again, it complies with no problem. I
am no way stuck on using these files. I am trying to get it to work and I want to use VB instead of C. If someone has something to try I am open to suggestions.
httpModules section: I think the modulename in your .config file needs to be changed from MyHttpModule to the class name which is TweakRequestModule. Your code looks fine otherwise, which is why you're not getting an error when you compile. It's just not registering
properly.
OK. It changed the web.config to read: and still no luck. Is there a way to see if the module is registering or not? I was successful at setting up a httpHandler off of a DLL, so I know the compiling and bin directory is working correctly.
The way i check is basically the what you're doing :) I don't think there is anyway to check the pipeline to see what modules have been loaded (there isn't any collection to my knowledge). This is bothering me now. I just wrote a simple httpmodule. here is
the code (C#): using System; using System.Web; namespace MyHttpModule { /// /// Summary description for Class1. /// public class TweakRequestModule : System.Web.IHttpModule { HttpApplication _context; public TweakRequestModule() {} public void Init(HttpApplication
context) { // get context _context = context; // register with event context.BeginRequest += new EventHandler(TweakRequest); } public void Dispose(){} public void TweakRequest(object sender, EventArgs e) { _context.Response.Write("HttpModule working."); }
} } Here is the config file: Here is the command line code to compile the module:
csc /t:library /r:system.dll,system.web.dll /out:MyHttpModule.dll TweakRequestModule.cs
I hit a default.aspx page that had only text in it. And "HttpModule Working." was written out to the file before the text in the page (so it worked). Try using this code and test it. If it doesn't work, then something is wrong on the computer itself
(cause i can't think of any other reason!)
OK. I used the above code and still no luck. For the C# code do I have to be concerned with the difference in versions between my computer and the server? If you look at the VB compiler, I tell it to use the older version. Sadly it still did not work. I am
beginning to wonder if it is a server problem. What permissions does the ASP.NET account have on the /bin directory. I do not think this is the problem, but I have to begin looking at the server. Do you have any suggestions?
To be honest, i'm glad it didn't work because it didn't look like anything was wrong with the code you had! :) It *must* be some sort of server problem, although for the life of me i couldn't say what. I think versioning may be a problem. But i'm unfamliar
in that territory. It *shouldn't* be a problem, but it must be if it's not working. Do you have any other servers you can test on? Perhaps ones with v 1.1 of the framework? Like i said, i compiled on my machine using 1.1 and ran it locally, then sent it to
the production server and (running 1.1) and it worked there as well, no problem. The ASP.NET account needs ACL permissions on the bin directory and the framework directory (i.e. C:\WINNT\Microsoft.NET\Framework\v1.x.xxxx). But if lack of permissions was the
case, you'd see an "Access denied" error. I think the best test would, as said, simply be to try testing it on another box running 1.1 (or install 1.1 on the machine? 1.0 and 1.1 can live harmoniously).
As a third check, I ran both the cs# and vb.net versions posted the c# version ran fine, the vb.net as supplied did not looked a bit closer, and the namespace as defined to register the httpModule was not correct, fixed this, then it worked fine use the following
format: You left out the myWebSiteName part of it Michael Khalsa / SilverEarth
1. HTTPModule's dll needs to be put the in the \bin folder of the web application. 2. In web.config, following code needs to be put within system.web element. where, AuthenticationModule is the class name and CustomAuthentication is namespace name. Alter it
with respect to your requirement. I did this and it works great at my end. If this doesn't help you out, please send me the code and I shall have it worked for you. Thanks,
Here is the working code: Imports System Imports System.Web Public Class TweakRequestModule Implements IHttpModule Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init AddHandler app.BeginRequest, AddressOf MyBeginRequest AddHandler app.EndRequest,
AddressOf MyEndRequest End Sub Public Sub Dispose() Implements IHttpModule.Dispose ' add clean-up code here if required End Sub Public Sub MyBeginRequest(ByVal s As Object, ByVal e As EventArgs) Dim app As HttpApplication app = CType(s, HttpApplication) app.Response.Write("
Request Begins Here...
") End Sub Public Sub MyEndRequest(ByVal s As Object, ByVal e As EventArgs) Dim app As HttpApplication app = CType(s, HttpApplication) app.Response.Write("
OK. We have gotten it to work but only if the web.config file is in the Parent directory. The site is hosted an I would like to be able to use in in a subdirectory instead of the parent. Any thoughts?
None
0 Points
7 Posts
httpModules do nothing
Apr 05, 2004 08:25 AM|cyrusthevirus|LINK
Request Begins Here...
") End Sub Public Sub MyEndRequest(ByVal s As Object, ByVal e As EventArgs ) Dim app As HttpApplication app = CType(s, HttpApplication) app.Response.Write _ ("Request Ends Here...
") End Sub End ClassMember
20 Points
491 Posts
Re: httpModules do nothing
Apr 05, 2004 11:07 AM|chapel21|LINK
None
0 Points
7 Posts
Re: httpModules do nothing
Apr 05, 2004 03:46 PM|cyrusthevirus|LINK
Request Begins Here...
") End Sub Public Sub MyEndRequest(ByVal s As Object, ByVal e As EventArgs ) Dim app As HttpApplication app = CType(s, HttpApplication) app.Response.Write _ ("Request Ends Here...
") End Sub End Class End Namespace I then compile this with the command line: vbc /sdkpath:d:\windows\microsoft.net\framework\v1.0.3705 /out:MyHttpModule.dll /t:library /r:System.dll,System.Web.dll TweakRequestModule.vb Again, it complies with no problem. I am no way stuck on using these files. I am trying to get it to work and I want to use VB instead of C. If someone has something to try I am open to suggestions.Member
20 Points
491 Posts
Re: httpModules do nothing
Apr 05, 2004 05:18 PM|chapel21|LINK
None
0 Points
7 Posts
Re: httpModules do nothing
Apr 06, 2004 10:00 AM|cyrusthevirus|LINK
Member
20 Points
491 Posts
Re: httpModules do nothing
Apr 06, 2004 10:06 AM|chapel21|LINK
None
0 Points
7 Posts
Re: httpModules do nothing
Apr 06, 2004 10:35 AM|cyrusthevirus|LINK
Member
20 Points
491 Posts
Re: httpModules do nothing
Apr 06, 2004 11:57 AM|chapel21|LINK
using System; using System.Web; namespace MyHttpModule { /// /// Summary description for Class1. /// public class TweakRequestModule : System.Web.IHttpModule { HttpApplication _context; public TweakRequestModule() {} public void Init(HttpApplication context) { // get context _context = context; // register with event context.BeginRequest += new EventHandler(TweakRequest); } public void Dispose(){} public void TweakRequest(object sender, EventArgs e) { _context.Response.Write("HttpModule working."); } } }
Here is the config file:Here is the command line code to compile the module:
csc /t:library /r:system.dll,system.web.dll /out:MyHttpModule.dll TweakRequestModule.cs
I hit a default.aspx page that had only text in it. And "HttpModule Working." was written out to the file before the text in the page (so it worked). Try using this code and test it. If it doesn't work, then something is wrong on the computer itself (cause i can't think of any other reason!)None
0 Points
7 Posts
Re: httpModules do nothing
Apr 06, 2004 12:42 PM|cyrusthevirus|LINK
Member
20 Points
491 Posts
Re: httpModules do nothing
Apr 06, 2004 01:55 PM|chapel21|LINK
None
0 Points
21 Posts
Re: httpModules do nothing
Apr 21, 2004 02:28 PM|Michael Khalsa|LINK
None
0 Points
21 Posts
Re: httpModules do nothing
Apr 21, 2004 02:30 PM|Michael Khalsa|LINK
None
0 Points
7 Posts
Re: httpModules do nothing
Apr 28, 2004 04:35 PM|cyrusthevirus|LINK
None
0 Points
150 Posts
Re: httpModules do nothing
Apr 29, 2004 02:32 AM|parmarkanaiya|LINK
Kanaiya Parmar
MCP, MCAD, MCSD
None
0 Points
1 Post
Re: httpModules do nothing
Jun 25, 2004 08:51 AM|Grigabyte|LINK
Request Begins Here...
") End Sub Public Sub MyEndRequest(ByVal s As Object, ByVal e As EventArgs) Dim app As HttpApplication app = CType(s, HttpApplication) app.Response.Write("Request Ends Here...
") End Sub End ClassNone
0 Points
7 Posts
Re: httpModules do nothing
Jun 30, 2004 08:26 AM|cyrusthevirus|LINK