I've a problem with the User.IsInRole function.
Here some screenshots and code:
My login form with return url (controlpanel)
My ControlpanelController code with the authorisations and my problem User.IsInRole:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WorkshopASPNETMVC_III_Start.Controllers
{
public class ControlpanelController : Controller
{
//
// GET: /Controlpanel/
public ActionResult Index()
{
if (User.IsInRole("Beheerder"))
{
return RedirectToAction("Beheerder");
}
else if (User.IsInRole("Student"))
{
return RedirectToAction("Student");
}
else
{
return View();
}
}
[Authorize(Roles="Beheerder")]
public ActionResult Beheerder()
{
return View();
}
[Authorize(Roles="Student")]
public ActionResult Student()
{
return View();
}
}
}
My debug on User.IsInRole:
Here you can see that it says that Name is empty and IsAuthenticated is false. This is what I get after I logged in as "Beheerder".
I made my own RoleProvider which is added in Web.config and with the appropriate appSettings. (Selection is because of my virtual machine that I am using.)
My CustomRoleProvider to get my role "Beheerder". The query that it is calling works.
When I debugged my 'problem' I found out that the breakpoint on adbc.getRollen(username) never gets reached. Anyone that had/has a familiar issue, or someone that can lead me in a right direction?