httpmodule

What are some best practices for managing background threads in IIS?

I have written an HttpModule that spawns a background thread. I'm using the thread like a Scheduled Task that runs in-process, which is really handy. What are best practices for keeping track of this thread? I've never done this before, and I'm a little confused about some aspects of it: How do I know if the thread is still running...

Can a request be handled and ended prematurely, early in the pipeline?

I have an HttpModule that has bound an event handler to EndRequest. Is there any way to handle the request inside the event handler? Meaning, I don't just want to run code and keep the request moving -- I want to stop it dead in its tracks, return a 200 Status Code, and call it a day, without it request continuing to the next step in t...

Debugging an httpmodule on the asp.net development server

Hi, I want to integrate some http modules in my asp.net application (v 3.5, visual studio 2008) and I'm not sure how to debug or use such modules while debugging in the asp.net development server that fires when I run the web app. Do I need to include the module source in the solution or can I just drop the DLL into BIN? I'm from the 1...

How do you persist data from one HTTP module to another and to the eventual handler?

From an HTTP module, is there a way to persist something in the Request to be accessed by a mater module or the eventual handler? Can you "stick" something on the Request as it passes through that will still be there later in the pipeline? ...

Why don't PreSendRequestHeaders and PreSendRequestContent run consistently?

When working with HTTP modules, has anyone noticed that the final two events in the pipeline -- PreSendRequestHeaders and PreSendRequestContent -- don't always run? I've verified that code bound to EndRequest will run, but will not when bound to either PreSendRequestHeaders or PreSendRequestContent. Is there a reason why? I thought pe...

How to register HttpHandler for all subfolders in Asp.Net?

I would like to register an HttpHandler to include all subfolders of a root folder regardless of how far down they are nested. I would have expected the behavior with the below code to do just that but in fact it only includes items directly in the root folder. <httpHandlers> <add verb="*" path="root/*" type="HandlerType, Assembly" /...

masterpage module override

I have a masterpage which is set via a HTTPModule on PreInit(). HAPPY TIME! Problem is I need to override the masterpagefile value on a few pages due to a layout issue. Anyone know the best way? I tried adding a Page_Preinit on my page, but it is executed before the PreInit() in my module, so it ends up being reset there. I'm thinki...

IIS 6: Enabling Virtual Paths

Hi, I've developed a simple file browsing HTTP module which uses virtual paths (i.e. paths that do not actually exist on the disk). The app. runs fine on my IIS 7, but on Win 2003 the IIS does not forward the HTTP requests to my Web. application - instead it just returns "The page cannot be found" to the browser. How do I disable this ...

Why can't I set an item in the HttpContext in a module then get it back in my handler?

In an HttpModule, I put an Item in the Context, like this: HttpContext.Current.Items.Add("MyKey", "Hello world!"); Directly under this code (still inside the module), I can retrieve this string from the collection, so I know it got added. Fast forward to my actual handler (a Web form -- .aspx). I try to get this item back: string my...

IHttpHandler vs IHttpModule

My question is simple (although the answer will most likely not be): I'm trying to decide how to implement a server side upload handler in C# / ASP.NET. I've used both HttpModules (IHttpModule interface) and HttpHandlers (IHttpHandler interface) and it occurs to me that I could implement this using either mechanism. It also occurs t...

Using HttpModule to Display Images

I have an HttpModule that displays images that follow a certain URL pattern. For example, /images/employees/jason.jpg is handled by the module, but all other images aren't. It works just fine on my local machine (Cassini and IIS 7). However, the IIS6 production server isn't working. I've had the hosting company map the images to the ASP....

How does IIS7 decide when to invoke…?

Hello, Q1) Assuming Http module is registered with IIS7 to be used for non-Asp.Net application ( say some Java app ) , when in the request’s life cycle will IIS7 invoke this module? Thus, how will IIS7 decide when to invoke it? Q2) In order to register Http module with IIS7, we need to put it in GAC. Is it possible to register H...

Does FormsAuthenticationModule detect whether …?

Hello, FormsAuthenticationModule is used for tracking user and role information using encrypted cookie. But does this module also contain code that actually detects whether user requesting web page has forms authentication ticket and if not, redirects user to login page, or is it actually UrlAuthorizationModule that tells FormsAuthe...

Taking /Pages out of the SharePoint URL?

A customer is asking if there is anything we can do to remove "/Pages" from his Internet-facing MOSS publishing site. Some Googling reveals that some clever use of HTTPModules may be able to hide the presence of Pages, but I've yet to see an end-to-end working solution. Have any of you come up against this particular requirement, and i...

Can I find out what domain made a request that triggered an HttpModule?

How do I find out from within an HttpModule what domain made a particular request? Say I only want to allow site1.com and site2.com to use images from my server, how do I check that it is them making the request? ...

How do I remove the header info using an HttpModule to Upload a file?

I've created an HttpModule in ASP.NET to allow users to upload large files. I found some sample code online that I was able to adapt for my needs. I grab the file if it is a multi-part message and then I chunk the bytes and write them to disk. The problem is that the file is always corrupt. After doing some research, it turns out t...

Why isn't my custom delivered image caching in the browser?

I have a custom handler that is returning an image to the browser. The images are fetched from a database. For some reason the images are not being cached by the browser, and I was wondering if someone might be able to spot what I am missing from the below code: HttpContext.Current.Response.BinaryWrite(imageBytes); HttpContext.Current...

HttpModule not running with Visual Studio

I am using an HttpModule to do some URL shortening on my site. I am using Visual Studio 2008 and IIS 7, and .Net 3.5. When the module is specified in the system.webServer element of web.config, and the site is run in IIS, it works fine. The config looks like this: <system.webServer> <modules> <add name="MinimizeModule" type=...

StatusCode in IHttpModule is always 200?

I have an custom IHttpModule that handels all available events and logs the HttpContext.Current.Response.StatusCode to a file. My web.config does not contain any other module in <httpModules> so all errors are promoted to the browser. Although the Browsers shows a 404, the log file is full of 200 (Ok) entries and not a single 404. Wh...

Processing static files via HttpModule in ASP.NET

I have statiс files in website folder, but need to check permissions for every file. I decided to use HttpModule for that purposes. ASP.NET receives all the http-requests (I used wildcard mapping) and The algorith is the following: HttpModule receives the request HttpModule checks permissions If access is denied then the answer is ...