Archive for March 2014
I have been working on a Dutch software for quite sometime now. A few of those source code translation worries lead to write TranslateMaid for Visual Studio. However on a day to day basis, we spend a lot of time on the web pages and documents. http://translate.google.com/ is always open at one of our browser tabs.
All of a sudden one day when we tried to translate Resterend budget per afdeling what we got is Rest Fuck budget per department. See it for yourself below. I don’t really know where the Rest Fuck came from. Some developer put in in there or the translation service was perplexed by itself.
However the Microsoft translator service was pretty ingenue in this case. It actually gave the correct translation.
You may also like Gimmick free Freebie from Microsoft Translator Preview service.
A slightly different version of this article was originally published for www.prowareness.com and could be located at http://www.prowareness.com/blog/access-control-through-asp-net-mvc-custom-action-filters/
HttpModule being the gatekeeper ASP.Net, one level down is the Action Filters for ASP.Net MVC. While managing large scale applications, it would not always seem very rational to create new Controllers for every functionality sometimes. You may also want to restrict access to specific controllers or specific action methods, and if you worked it through you would end up with a code snipped like below. An if else condition everywhere you wanted access control.
Which is obviously redundant and does not reflect on code reusability principle. So you may choose to create a custom HttpModule for access control during the initial ASP.Net request pipeline, of if that is not a possible solution in your case (or like the one above in ASP.Net MVC), then you must be looking at building a custom action filter. Once you have that in place, you could decorate your required action methods with your access control custom filter, or the entire controller, or as a global action filter (post ASP.Net MVC 3) so that the action filter would get invoked on every controller in the application.
Below is the code snippet showing the bare minimal implementation of a custom action filter for access control. In case the current request does not come from an Administrator, then it redirects him to an AccessDenied action method in the CompanyController.
The if else statements in the first snippets would take a little more elegant, and neat form.
Thus you would have a simple, elegant, and powerful access control mechanism via a custom action filter. If you like this kind of cleanliness in non MVC projects, please take a look at POSTSHARP as well.