Conditional Authentication / Authorization Approach

K

KW

I have the following fairly simple scenario. I have a set of pages that
require users to be authenticated ONLY when certain other conditions
are true. For example...

These two pages require users to ALWAYS be authenticated:
- PageA.apsx
- PageB.aspx

While these two pages only require users to be authenticated on
"tuesdays".
- PageC.aspx
- PageD.aspx

This is a silly example, but it shows that the condition is not user
related, but rather environment or configuration related.

I am trying to determine a simple way to handle this without having to
write a bunch of conditional logic in every page. My first thought was
to use page inheritance somehow, but this seems like a job for roles,
membership, and authorization using the web.config file to specify
authorization rules.

I just can't figure out how to appoach this example. Any help would be
greatly appreciated!

Thanks!
 
D

Dominick Baier

You can handle the AuthorizeRequest event in a module or global.asax - this
code gets implicitly called on every request

Here you can check for the url and other conditions and if the user is not
authorized, you set

Respone.StatusCode = 401;

and call Application.CompleteRequest();

this is exactly how the built-in authorization does its work.
 

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
474,266
Messages
2,571,082
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top