On an intranet site using windows authentication, and certain controller methods being marked with the "AuthorizeAttribute" controlling access to certain users/groups and roles, I'm trying to figure out the best way to allow "test users" to access these things.
Since <location> is off the table with MVC (security concerns), what is the best approach here?
My first thought is to implement the following:
Is there an easier/better way???
Update What I originally wrote used the attribute syntax on a class or method, but if you are using MVC3 you can also use a global action filter in (global.asax.cs) so you only have to do it once.
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
#if DEBUG
filters.Add(new AuthorizeAttribute() {Users="YourAccount"});
#endif
//Your other global action filters
}
Original You could use #if DEBUG to only add the authorization to debug code.
#if DEBUG
[Authorize(Users = "YourAccount")]
#endif
The Authorize attribute allows multiple so you don't have to repeat your production authorized user list or use an #else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With