This can be done by making a new HTTP handler, but is there a simple way to configure the following?:
- Site is setup on basis of user accounts with username say A001, A002….etc.
- Once a user logs in they can access their resources in their directory (/A001) etc…which may contain files and images
The issue that I have had using roles and authorization in ASP.NET is that roles are either generic (defined by roles, example anyone logged in may be able to access the resource) or hard coded in the web.config files which is clearly not feasible in a dynamic environment where user accounts are being created:
<authorization>
<allow users="John"/> // allow John only
<deny users="*"/> // deny others
</authorization>
Is there a simple way to ensure that only a certain user has access to their folder only?
Well using an HTTP Module would be simple enough.
First this is the request life cycle:
For more info: http://msdn.microsoft.com/en-us/library/system.web.httpapplication.aspx
I think the best event that fits your needs is the
Application_AuthorizeRequestHere you could get the path being accessed, and you could have a map in your database associating your uses with their allowed paths, something like:
Then in the event read this map and decide if the user should be authorized or not