Reputation: 39
I want to create custom authentication with MVC3.
Scenerio:: User will have a login form, where he will input userId and password. These credentials are then verified against my business logic. I can not use default process, like validating it from User table then assign role etc..
My business logic will provide me a boolen value IsValidUser and UserRole.
PROBLEM:: I need to do two things:
1. Use these values returned by Business logic in AuthoriseAttribute filter. So that I can restrict a user from accessing any particular action of a controller.(I have tried putting these values in Session variable, but not able to use them in Authorisation filter.)
2. How to use Formsauthentication.Setauthcookie for accomplishing this task.
Upvotes: 1
Views: 113
Reputation: 265
For custom authentication you can use "ActionFilters" class for authorizing perticular controller and you can pass those parameters which you get from your "buisness logic" in the form of property,
Action Method,
[MyActionFilter(Property1 = "Value1", Property2 = "Value2")]
public ActionResult Index()
{
return View();
}
And Action Filter would be like
public class MyActionFilter : ActionFilterAttribute
{
public string Property1 { get; set; }
public string Property2 { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
}
}
Upvotes: 3