httpmodule

Advanced: How many times does HttpModule Init() method get called during application's life?

Web application initialization is as follows: As we know when IIS receives the first request for a particular Asp.net application resource, IIS creates an instance of a HttpApplication (defined in global.asax codebehind). When this new instance is created it's initialization happens that also checks all configured HTTP modules. All mod...

ASP.NET URL remapping &redirection - Best Practice needed

This is the scenario: I have a list of about 5000 URLs which have already been published to various customers. Now, all of these URLs' location has changed on my server side. The server is still the same though. This is a ASP.NET website with .NET3.5/C#. My requirement is : Though the customers use the older source URL they should be...

CompleteRequest in HTTPModule's OnError event

I have set up a HTTPModule that intercepts an ASP.NET applications OnError event, to log the error in a database. However, what I am finding is that if the exception occurs in a loop, the page seems to continue executing (with all the errors logged as well). This is the code for the HTTPModule's OnError event: ETILibConfiguration err ...

IIS module and WCF

I have written an IIS module (base IHttpModule) that does some custom (OpenAuth) authentication before preceding to my WCF REST service. I have extended GenericPrincipal to track my user, with an IIdentity, and set the context.User field to my new principal: application.context.User = principal However, when I receive the context in WC...

How to dispose IHttpModule correctly?

All implementation of IHttpModule I've seen looks following: class HttpCompressionModule : IHttpModule { public void Init(HttpApplication application) { application.SomeEvent += OnSomeEvent; } private void OnSomeEvent(Object source, EventArgs e) { // ... } public void Dispose() { // nothing here !!! } }...

Bypass existing HttpModule for a http handler.

Scenario: I have a bunch of web applications for which I want to add a simple ping functionality via http handler. Example: Http://myserver/foo/testfolder/ping.me Problem: For some of the applications this approach does not work becasue of custom HttpModule. These modules have some depedency on either authentication or some other proces...

Help reading JSON from HttpContext.InputStream

I have created a HttpModule to capture requests for auditing purposes. For Ajax requests to a web method I would like to also log the JSON data associated with the request. E.g Request POST /MyPage.aspx/AddRecord HTTP/1.1 x-requested-with: XMLHttpRequest Accept-Language: en-gb Referer: http://fiddlerlocal:5000/AddRecord.aspx ...

HTTPModule Only Getting Called Once Per Page

Hello all, I am trying to implement a custom HTTPModule for ASP.NET. I have a very simple html page with an image in it and an HTTPModule that hooks into the BeginRequest event. When I debug with Visual Studio's dev web server, my module is called twice: one for the initial page request, then once for the image request. This is what ...

Save username in session variable when users logins using Http Module

Hi, Is it possible to use an application event to save the username in a session variable? I would like to do something like this: private void ContextOnBeginRequest(object sender, EventArgs eventArgs){ if (_context.Request.IsAuthenticated) _context.Session["ID"] = _context.User.Identity.Name; } However...

ASP.NET HttpModule gives "Connection Reset" in browser

I have implemented a HttpModule in ASP.NET (framework 2.0). From my logging on the server, I can see that the http request is being picked up by my HttpModule, and my code runs successfully (writing content back to the Response stream). However, the web browser (IE, FF, Chrome, all the same) just give me a "connection reset" error mess...

HTTPModule invoked on main page but not on sub-page

Hi All, I am facing a strange error in MOSS 2007 running under Windows 2008. I have created a custom HTTP Module that fires on the application's OnAuthenticate event. It basically creates a custom cookie which is used by another application to authenticate the user, creating a single sign-on effect. Everything went fine under the de...

DatabaseFileLockedException driving me crazy

I am following the example here: http://developer.db4o.com/Forums/tabid/98/aft/10114/Default.aspx to setup my MVC2 app with db4o using an HttpModule. I also have a LINQPad instance open to query the data as I develop. The web app seems to work like a charm, but LINQPad keeps getting DatabaseFileLockedExceptions until I close down the w...

HttpModule threading

Trawling through the 'net I'm getting lots of conflicting posts as to whether the HTTPModule route is single threaded or multithreaded by default. I'm trying to debug rapidly differing performance within local, UAT and deployment environments and am wondering whether there is a pinch point with HTTPModule that I've been previously unawa...

IHttpModule handling sockets

I had assignment to implement some custom encryption scheme on IIS. I first checked out ISAPI filters, but found out that they are deprecated and SSL is no go, because of device limitation and I was unable to find low resource native encryption supported by IIS. I am playing whit HttpModules. So when I catch BeginRequest I store HttpAp...

ASP.NET HttpModule : detect first request in a session

I have written a HttpModule for our site which generally accepts requests and checks for specific file extensions as well as the value of a specific session variable. Is it possible to detect the first request in a session? ...

ASP.NET Redirect to other page internal

Is there a way to redirect a asp.net page to another and restart the server workflow without the user seeing it in their browser? Call to .NET Page (handled by routing) Perform some actions based on this call Call other webpage internal (handled by a httpmodule) The internal page don't "exist" (passes though a module that performs...

HTTP Module and Cookies in Sharepoint 2007

I have some proof concept code for a HTTP module. The code checks to see if a cookie exists, if so it retrieves a value, if the cookie does not exist it creates it and sets the value. Once this is done I write to the screen to see what action has been taken (all nice and simple). So on the first request the cookie is created; subsequent...

Best HttpApplication event for altering the response source

I intend to build a HttpModule in order to scan a response's source and make small adjustments, mainly altering urls (hrefs, actions, srcs, etc). I see the HttpApplication has a plethora of events that can be handled and I'm not sure of the best stage at which it's safe to alter the HTML content that goes back to the browser. I need to...

HttpModule.Init - safely add HttpApplication.BeginRequest handler in IIS7 integrated mode

My question is similar but not identical to: http://stackoverflow.com/questions/1123741/why-cant-my-host-softsyshosting-com-support-beginrequest-and-endrequest-event (I've also read the mvolo blog referenced therein) The goal is to successfully hook HttpApplication.BeginRequest in the IHttpModule.Init event (or anywhere internal to the...

Recycle IIS 6 AppPool set unhealthy flag

In an ISAPI Extention there is a way to programmatically flag an IIS AppPool as unhealthy, which means that it will be recycled on next access. (e.g. pecb->ServerSupportFunction(pecb->ConnID,HSE_REQ_REPORT_UNHEALTHY,UNHEALTHY,NULL,NULL); Is there any way to do the same using a .Net HttpModule? There is a HttpRuntime.UnloadAppDomain(), b...