473,748 Members | 9,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpModule or Global.asax

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
Nov 17 '05 #1
1 1395
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
"Juha Borenius" <mr********@hot mail.com> wrote in message
news:eQ******** ******@TK2MSFTN GP09.phx.gbl...
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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1001
by: Nick | last post by:
My HttpModule is only executing on the first run of the application? What would cause this to happen? This is a module that I am using to Authenticate requests instead of a Global.asax. This is really baffling to me. I also tried Global.asax and got the same results, anybody else experience this? Thanks, Nick
3
3757
by: Michael Iantosca | last post by:
I have a custom attribute that I attach to certain pages in my application and I want to inspect each page request as it is made to see if the custom attribute is attached to the underlying page class. If is attached I want to perform some action. How can I access custom attributes from an HttpModule? I have to pass a target to the System.Attribute.GetCustomAttribute() call to attempt to retrieve the attached attribute. I tried to access...
2
2161
by: Will | last post by:
Hi, I am having trouble with a HttpModule which is registered to handle the HttpApplication.Error event. All works well until I throw an error from within the Session_End or Application_End event handlers in the global.asax.cs file - the HttpModule event handler I attached to the Application.Error does not run under these circumstances! Can anyone explain why? Thanks in advance, Will
1
1615
by: David B. Bitton | last post by:
I moved Authentication code from an HttpModule to the Global.asax file. It was _not_ "sticking" when I set my custom IPrincipal, but it "stuck" when I did the assignment in the global.asax. Why? -- -- David B. Bitton david@codenoevil.com www.codenoevil.com
2
4973
by: Holly Li | last post by:
Hi, I am following the example in .net's help doc--"Securing XML Web Services Created Using ASP.NET" I have copied all the code from the example but couldn't make it to work. The problem is that inside the method: private void OnAuthenticate(WebServiceAuthenticationEvent e) { if (_eventHandler == null) return;
1
1105
by: Kevin Burton | last post by:
I have an HttpModule that I want to communicate to a .NET remoting server. Normally I do something like: RemotingConfiguration.RegisterWellKnownClientType(typeof(RemotingObject), "tcp://localhost:9400/RemotingServer/visa.dps.ppc.RemotingObject.rem"); This does some "magic" so whenever I instantiate the RemotingObject it is connected to the server. This works fine for clients that I have relative control over but with an HttpModule I am...
3
2015
by: Samuel | last post by:
nHi, is it possible to add pure code to APP_Code folder to act as an HTTPModule? If so, how do I reference it in web.config? I know global.asax is the place for such thing but I am just wondering.
11
8374
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the generated code on a W2K3 server the application_start and any other event on the global.asax file won't fire. I added tracing and logging to make sure and I can see the code is just not execution. When running the same exact (deployed etc.) code on...
8
13205
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project compiles & runs fine locally, but when I copy to the production machine, I get this error: Parser Error Message: Could not load type 'Global'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="Global" %> Source...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.