HttpModule or Global.asax

J

Juha Borenius

I have a web site that requires some directories to be protected with
password. Directories might contain any kind of files from aspx -pages to
pdf -documents. Protected directories are not virtual directories - there's
only one application. Protection must be controlled from program - so
authentication methods provided by framework don't seem to work as there's
only one web.config -> can't control each directory independently. I think
editing web.config from program is also a problem.

I found three ways to do it.

a) Implementing HttpModule that handles request at very early stage
(OnBeginRequest). If required file is under protected directory and user has
not logged in (knowing from session state) request is directed to other
directory (or to some special login page).

b) Same thing could be implemented in global.asax as it can be attached to
OnBeginRequest.

c) Implementing HttpHandler that does about the same thing. Handler should
be attached to every type of request (POST, GET and HEAD) and for every file
type.

In every case I would save protected directories to Application, so it
should be pretty quick and easy to compare if current request is under
protected directory. List of protected directories will be refreshed from
database at certain interval. Interval is not a problem.

Are there other options to think of?
What would be the best solution as it should be reliable, scalable etc.?

Regards,
Borre
 
S

S. Justin Gengo

Juha,

You can control access to each directory from the single web.config file.

I have sample code to do so on my web site, www.aboutfortunate.com. Just go
to the code library and search for: "use web.config to protect folder" or
something similar.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top