5

I can spin up a standard asp.net mvc 4 intranet project and decorate the controller or methods with things like:

[System.Web.Mvc.Authorize(Roles = "MyApp Users")]

I have tested it and it will work perfectly (since my domain account is a member of the "MyApp Users" in Active Directory)

However my problem/question is how do I get the same type of behavior for a "Hot Towel" application? I try decorating my breeze controller, HotTowel Controller, or any method with the same attribute and I can never authenticate... what gives?

Your help is greatly appreciated.

2
  • Do you have a role provider setup? Check the IPrincipal and see if your are signed in also. Mar 26, 2013 at 12:54
  • I'm using the default role provider for asp.net mvc... nothing custom. And yes, if I check the IPrincipal it shows me as logged in.
    – Mr.Hardy
    Mar 26, 2013 at 18:00

1 Answer 1

5

Finally figured it out. I hope this is of use to others.

First you must set the WindowsProvider as your roleManager like so:

<roleManager defaultProvider="WindowsProvider"
   enabled="true"
   cacheRolesInCookie="false">
  <providers>
    <add
      name="WindowsProvider"
      type="System.Web.Security.WindowsTokenRoleProvider" />
  </providers>
</roleManager>

Then you will be able to check the roles for the user [using Roles.IsUserInRole()], and more specifically to this question use the authorize attribute. The only thing is that you will have to include the domain in the authorize attribute, like so:

[System.Web.Mvc.Authorize(Roles = "YourDomain\\MyApp Users")]

And now everything works as you would expect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.