views:

132

answers:

3

I'm working with ASP.Net MVC and I would like to make a web site accesible via the internet, but only to a select few people right now. I want to do something basically exactly like the beta access page with password just like they did on stackoverflow, serverfault, and superuser.

I don't just want to check and redirect in the home controller, I want it to always go there no matter what url is used.

Anyone know how they do it?

A: 

The easy way is to put something in the users session. Run a check either on the master page or in an http handler to see if this session is correct or not. If not redirect to the password capture page. When the password is provided then set the session variable...wa la they are in.

If you want to remember them then also drop a cookie and add that to your check as well.

Andrew Siemer
It's the controller's responsibility to decide how to handle an incoming request, right? I'd try to keep that decision out of the UI layer.
Andy Gaskell
+1  A: 

I don't know enough about MVC in particular, but it would probably mean creating a base controller and overriding OnActionExecuting or OnAuthorization.

Andy Gaskell
This is what I was leaning towards, but I'm hoping somebody that knows asp.net mvc better than me can tell me about some extensibility point that will be a little cleaner.
Max Schmeling
The only alternative I see is applying filter attributes to all of your actions. That wouldn't be fun :)
Andy Gaskell
You can filter at the class level, which is much easier to manage.
swilliams
+1  A: 

I'd create a custom filter that extended AuthorizeAttribute. That way you can put it on the controllers/actions you wanted, and remove it easily enough. Since it's essentially a decorator, you would be playing nice with the Open/Closed principle too.

If you override AuthorizeCore you can check session/cookie/whatever for the login and if that passes, run the base AuthorizeCore too.

swilliams