0

I've a problem with the User.IsInRole function.

Here some screenshots and code:

My login form with return url (controlpanel) 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". 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.)

enter image description here

My CustomRoleProvider to get my role "Beheerder". The query that it is calling works.

enter image description here

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?

Bilzard
  • 371
  • 1
  • 5
  • 19
  • Perhaps this is usefull? http://stackoverflow.com/questions/15567338/user-isinrole-doesnt-work – faester Oct 07 '14 at 21:41
  • I have tried it and it is the same outcome. And the VS2013 doesn't find [InitializeSimpleMembership]. – Bilzard Oct 07 '14 at 21:46
  • Since you aren't using SimpleMembership, have you created your own implementation of Identity, IPrincipal for your User class? I can't tell from your screenshot, but does your customroleprovider also override the IsUserInRole(...) method? – failedprogramming Oct 07 '14 at 22:02
  • I have overridden it multiple methods including IsUserInRole, all the overridden methods return 'throw new NotImplementedException();' except GetRolesForUser as seen in the picture. – Bilzard Oct 07 '14 at 22:08

0 Answers0