Sunday, 25 August 2013

authorization check in the attribute

authorization check in the attribute

I want to implement a redirect unauthorized user with a check in the
proper attribute. To do this I create a class attribute with a constructor
with no parameters.
[AttributeUsage(AttributeTargets.Method)]
public class LoggedAttribute:Attribute
{
public LoggedAttribute()
{
//TODO
}
}
Now assign this attribute to all methods of action that requires
authorization.
[Logged]
public ViewResult SendMessage()
{
return View();
}
I have a User model with boolean flag IsLoggedIn. How can I check this
flag in the class attribute to redirect the user to the authentication
page in case of an emitted flag ?

No comments:

Post a Comment