Search code examples
asp.net-mvc-2windows-authentication

MVC2 Login verification with windows Basic authentication


I am using windows basic authentication, if user is verified home controller is displayed. Only user those who belong to "Admin" group are allowed to access this site. so far all works well. I am using below code. I want to log message in database if user tries to login and does not belong to "Admin" group. Any suggestion how to achieve that?

[Authorize(Roles = "Admin")]                
public ActionResult Home()
{
..............
return View();
}

Thanks,


Solution

  • You have 2 options, write a custom authorize attribute which logs on failure or create an HTTPModule which detects 401's and logs there. Personally i prefer the custom authorize attribute approach