views:

23

answers:

2

I have a website on IIS 7. This website has a HttpModule with an AuthorizeRequest event handler. This event does not fire for CSV files and I can access the file without logging in, I guess this is because IIS7 is not configured to require form autentication for CSV files.

How can I set this?

A: 

This will impact all files, but you can add a mapping to your server configuration:

  1. Go to the properties of your website and click on "Handler Mappings".
  2. In the upper right corner click, "Add Module Mapping".
  3. Put "*.csv" in the Request Path.
  4. Select "IsapiModule" for module.
  5. Find the aspnet_isapi.dll in the framework folder of the appropriate .net framework you are using under Executable.
  6. Give it a name.
  7. Check the tabs in "Request Restrictions" for more options.

This should force any .csv request to parse through asp.net (thus invoking formsauthentication) before servicing the request.

EDIT: Alternatively you can add a wildcard script mapping as desribed here: http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/

This will force authentication to all non-.net files (pdfs, docs, anything).

Joel Etherton
I still can access the file with no authentication and AuthorizeRequest is not fired... Can you think of anything I can check?
Lince81
@Lince81 - see edit.
Joel Etherton
The recommendation that is given here will only work if your Application Pool is running in Classic Mode, if your app pool is running in Integrated Mode you want to probably enable Forms Authentication and your module for all requests. See: http://learn.iis.net/page.aspx/244/how-to-take-advantage-of-the-iis7-integrated-pipeline/
CarlosAg
@CarlosAg - You should put that as an answer as well in case it turns out to be the OPs solution.
Joel Etherton
Hi, my application pool is running in classic mode. Tryed to add the wild card and now when I ask for the csv file a "Windows sevurity" window pops up asking user and password, it looks to me that is using windows authentication and not form authentication. I might have changed something while trying to fix the problem...
Lince81
@Lince81 - what version of .Net are you using?
Joel Etherton
@Joel - if I go in application pools, right click on default and "Basic settings" it says ".Net Framework v2.0.50727"
Lince81
@Lince81 - then in the wildcard mapping you should be using the file: C:\Windows\Microsoft.Net\Framework\v2.0.50727\aspnet_isapi.dll to achieve this effect.
Joel Etherton
A: 

Hi, this answer explains how to achive what I was looking for. I inserted in web.config the lines in chapter 3 and 4 of the referenced guide, and changed ".htm" with ".csv", maybe someone can optimize the solution for *.csv files. but for me it does what I needed.

Lince81