문제

In rails I could do something like this to make sure a user is authenticated before accessing an action in the controller:

before_filter :checked_logged_in, :only => [:edit, :update]

I was wondering if ASP.NET MVC had something similar or if there was a framework out there that could essentially do something like the following:

For certain methods with actions that take a certain parameter, I want to point the action to a method, check to see if the user owns that object, and if so, proceed to the controller action. If not, I want to redirect him to another action where I can show him he has invalid credentials.

So basically I am looking for a sort of "before_filter." Anyone know of anything out there that can do this? Thanks!

도움이 되었습니까?

해결책

They are called Action filters in ASP.Net MVC, you can read more here http://www.asp.net/mvc/tutorials/understanding-action-filters-cs.

Asp.net MVC comes with an Authorize filter to indicate actions that requiere the user to be authenticated.

Usage:

[Authorize]
public ActionResult Index()
{

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top